Topic: Defect report: integral-to-boolean conversion in converted


Author: "Richard Smith"<richard@metafoo.co.uk>
Date: Wed, 19 Oct 2011 15:24:18 -0700 (PDT)
Raw View
Hi,

In both C++98 and C++11, the following code appears to be ill-formed:

   template<bool b>  struct S {};
   S<0>  s;

However, EDG, g++ and clang all accept it. The reason this is ill-formed is
that the non-type template argument is a converted constant expression of type
'bool' (see [temp.arg.nontype]p5), and the second conversion in the implicit
conversion sequence is a boolean conversion, which is not allowed in the
conversion for a converted constant expression (see [expr.const]p3).
Conversions in the other direction (from 'bool' to integer types) are
permitted here, since they're integral promotions.

Suggested resolution: In [expr.const]p3, add "boolean conversions from
integral or unscoped enumeration type other than narrowing conversions" to the
list of conversions allowed in a converted constant expression.

Thanks,
Richard


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]




Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?=<daniel.kruegler@googlemail.com>
Date: Tue, 25 Oct 2011 09:59:26 -0700 (PDT)
Raw View
Am 20.10.2011 00:24, schrieb Richard Smith:
>  Hi,
>
>  In both C++98 and C++11, the following code appears to be ill-formed:
>
>      template<bool b>    struct S {};
>      S<0>    s;
>
>  However, EDG, g++ and clang all accept it. The reason this is ill-formed is
>  that the non-type template argument is a converted constant expression of type
>  'bool' (see [temp.arg.nontype]p5), and the second conversion in the implicit
>  conversion sequence is a boolean conversion, which is not allowed in the
>  conversion for a converted constant expression (see [expr.const]p3).
>  Conversions in the other direction (from 'bool' to integer types) are
>  permitted here, since they're integral promotions.
>
>  Suggested resolution: In [expr.const]p3, add "boolean conversions from
>  integral or unscoped enumeration type other than narrowing conversions" to the
>  list of conversions allowed in a converted constant expression.

Forwarded to CWG.

It seems to me that the actual issue is, whether it is clear or not that
[conv.integral] p4 already implies what you are suggesting here.

Greetings from Bremen,

Daniel Kr   gler



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]