c++/7576: ?: used with static const member variables creates undefined reference

edA-qa mort-ora-y edA-qa@disemia.com
Mon Aug 12 04:29:00 GMT 2002


I think I may actually be confused with item 9.4.2.4 of the standard. 
I've forgotten the out-of-class references, I'm just not convinced 
that they are needed (although I'm willing to accept it if this is 
causing more annoyance than anything more).

The excerpt, "... 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..."

I assumed that the first part indicating used in constant expressions 
is what is allowed the "static const" members to be used in 
statements like if, and array sizes, without needing the out-of-class 
declaration (as my example shows such cases which work).  

The second sentence says "if they are used", does this imply that any 
use of the variable requires the out-of-class definition -- in which 
case gcc is then (as shown in my example) compiling code which is not 
actually compliant (thereby allowing you to write invalid code).

The example shows how I can simply replace the ?: operator with an 
equivalent if/else statement avert the problem.  If this is not a bug 
then I would assume the if/else variant should also produce a 
compilation or linker error, as it is then not valid code.  Or am I 
missing something?

Sometime around 12 Aug 2002, nathan@gcc.gnu.org inscribed:

> Synopsis: ?: used with static const member variables creates undefined reference
> 
> State-Changed-From-To: open->closed
> State-Changed-By: nathan
> State-Changed-When: Mon Aug 12 01:33:30 2002
> State-Changed-Why:
>     not a bug. You have not included an out-of-class
>     definition of your static members. See [9.4.2]/4
> 
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7576

--
edA-qa mort-ora-y

I know the truth is a myth, but that doesn't mean I'll stop searching 
for it.




More information about the Gcc-bugs mailing list