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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 :)

Benoit

2010/11/6 ZdenÄk Sojka <zsojka@xxxxxxxxx>:
> 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
> };
>
> struct A {
> Â Â Â Âstatic const int y = (int)x;
> };
> ===================
>
> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux