This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3800: A value of const static class attribute cannot be used in STL
- To: Milan Krčmář <milan dot krcmar at debis dot cz>
- Subject: Re: c++/3800: A value of const static class attribute cannot be used in STL
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 27 Jul 2001 06:39:24 -0300
- Cc: <gcc-bugs at gcc dot gnu dot org>, <gcc-prs at gcc dot gnu dot org>, <nobody at gcc dot gnu dot org>
- Organization: GCC Team, Red Hat
- References: <Pine.LNX.4.30.0107271056030.15161-100000@net3000.dsh.cz>
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