This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]