[C++0x] code that used to be accepted isn't accepted anymore (related to constexpr changes?)

Jason Merrill jason@redhat.com
Sun Nov 7 07:20:00 GMT 2010

On 11/06/2010 02:37 PM, Gabriel Dos Reis wrote:
>>> static const unsigned x = (unsigned)-1;
>>> enum e {
>>>         ey = (int)x
>>> };
> The compiler is right: the value of `x' cannot fit in an int, therefore the
> declaration is ill-formed.  This has nothing to do with constexpr.

It does have to do with the definition of a constant expression, though.

4.7 says, "If the destination type is signed, the value is unchanged if 
it can be represented in the destination type (and bit-field width); 
otherwise, the value is implementation-defined."

That suggests to me that (int)x is a constant expression with 
implementation-defined value, and g++ is wrong.


More information about the Gcc-help mailing list