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

Re: static const int optimization fails in conditional expressions




Please stop cc'ing gcc-gnats@gcc.gnu.org, by the way.  That only works for
appending to an existing PR, and there is no PR to append to.  So their
GNATS database pukes.



On Tue, Dec 11, 2001 at 11:18:45PM -0600, James E Jurach Jr. wrote:
> > Compilers are allowed to optimize static const integral members, in the
> > sense that their values may be used directly.
> 
> Right.  I'm reporting that
> 
> 1) gcc's behavior changed in this regard in 2.96 and 3.00 from 2.95 and
>    previous, and 

GCC was buggy.  Now it's fixed^H^H^H^H^Hless buggy.


> As I understand, gcc used these values directly with the described
> conditional expression in 2.95, so that there was never a need to define
> these variables.
> 
> > That has nothing to do with the requirement that static members must
> > still be defined.
> 
> On this requirement, gcc is not consistent:

Let me be more clear:  this requirement is not from GCC, it's from the
C++ standard.  There is no optimization bug in GCC to fix.

#    The declaration of a static data member in its class definition
#    is not a definition and may be of an incomplete type other than
#    cv-qualified void. The definition for a static data member shall
#    appear in a namespace scope enclosing the member's class definition.
[...]
#    If a static data member is of const integral or const enumeration
#    type, its declaration in the class definition can specify a
#    constant-initializer which shall be an integral constant expression
#    (5.19). In that case, the member can appear in integral constant
#    expressions within its scope. ***The member shall still be defined
#    in a namespace scope if it is used in the program and the namespace
#    scope definition shall not contain an initializer.***

                                                *** emphasis added ***

This is from [9.4.2]/2 and /4.

You wanted a quote from somebody with a copy of the standard; there
you go.  :-)


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



Reply to: