[Bug c++/20547] undefined reference to "static const" fields of classes

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sat Mar 19 14:03:00 GMT 2005


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-19 14:03 -------
(In reply to comment #2)
> But according the standard, 'const static' data members of an intergral type can
> now be initialized _inside_ their class. In this case, the initialization is
> _also_ a definition, so _no_ further definitions are reuquired outside the class
> body.

No it is not a definition, a definition (or is it the other way around).  Still this is invalid.  Yes the compiler 
is allowed to "optimize" the constant which is why it worked in 2.95.3 (well because the defintion of 
push_back was wrong).

Oh, one more thing, the vector code is equivalent to (so you take the address):
struct T
{
  static char const a = 3;
};
void
fff(const char &a){ }
int
main()
{
  fff(T::a);

  return 0;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20547



More information about the Gcc-bugs mailing list