C++ static integer class constants...

Florian Weimer fw@deneb.enyo.de
Mon Oct 17 19:17:00 GMT 2005


* 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.



More information about the Gcc-help mailing list