This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++ static integer class constants...
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: "John Ratliff" <webmaster at technoplaza dot net>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 17 Oct 2005 21:16:35 +0200
- Subject: Re: C++ static integer class constants...
- References: <87oe5pb5dp.fsf@totally-fudged-out-message-id>
* John Ratliff:
> On comp.lang.c++, Victor Bazarov says my example program is well-formed
> standard C++ according to the ISO C++ standard.
>
> "Since their address is never taken, the 'foo::A' and 'foo::B' are, in
> fact, compile-time constant expressions that do not require storage.
> The objects, therefore, don't need to be defined outside of the class
> definition.
This analysis argues from the implementation, not from the standard.
The standard requires that you provide a definition if you use the
constant in a place which does not *require* a constant expression.
In other words,
int foo[Class::static_const_member];
is fine without a definition, but
int bar = Class::static_const_member;
is not.
It's strange and smells like a mistake in the standard.