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 Sat, Nov 6, 2010 at 12:30 PM, Benoit Jacob <jacob.benoit.1@gmail.com> wrote:
> I'm not a GCC dev; but I believe that it's normal that this code gets
> rejected. There's nothing in the c++98 or c++0x specs that guarantees
> that constant global variables are actually constant --- as you could
> in theory take pointers to them, const_cast, and dereference. It just
> so happens that (at least here on gnu+linux) gcc puts such constant
> global variables in a read-only segment, so that doing that is an
> access violation. In other words, it was pretty unsafe that GCC
> accepted this code and I'm glad to head it is now rejecting it :)

That makes no sense to me.

>
> Benoit
>
> 2010/11/6 ZdenÄk Sojka <zsojka@seznam.cz>:
>> Hello,
>>
>> the following code used to be accepted in 4.5.1, but isn't anymore in current trunk:
>> ======= test.C =======
>> 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.

>>
>> struct A {
>> Â Â Â Âstatic const int y = (int)x;

Likewise.

You can however fill a bug report requesting a more illuminating
diagnostic.

-- Gaby


>> };
>> ===================
>>
>> The error message is:
>> $ g++ -std=c++0x test.C
>> test.C:4:12: error: '-0x00000000000000001' is not a constant expression
>> test.C:4:12: error: enumerator value for 'ey' is not an integer constant
>> test.C:8:28: error: field initializer is not constant
>>
>> Is this code going to be rejected in final 4.6.0, or is this just a temporal change?
>>
>> Thanks in advance,
>> Zdenek Sojka
>>
>


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