c++/3800: A value of const static class attribute cannot be used in STL

Alexandre Oliva aoliva@redhat.com
Fri Jul 27 02:39:00 GMT 2001


On Jul 27, 2001, Milan Krčmář <milan.krcmar@debis.cz> wrote:

> If I define any constant static member array|struct with value inside
> class body, the compiler emits an error. The error is not emited for
> constant static int and unsigned (and probably all the simple types as
> char, ...). If, according to the standard, it is not allowed to define (=
> together with its value)  simple const static members inside class body,
> the compiler should emit an error, too.

You are allowed to declare with an initializer a static data member of
constant integral type inside the class body, but this doesn't mean
you don't have to define the static data member outside the class
body.  In C++, for every:

class foo {
  static ..... bar;
};

there must be a:

.... foo::bar;

outside the class body, regardless of the type or constness of
foo::bar.  If foo::bar is of constant integral type, and the
initializer is given inside the class body, foo::bar may be used in
constant expressions, and the definition must not contain an
initializer, but the definition must still be present.  If you don't
believe this, see [class.static.data]/4.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me



More information about the Gcc-bugs mailing list