This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
- From: "matthieu dot imbert at ens-lyon dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 29 Jul 2011 10:37:36 +0000
- Subject: [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
- Auto-submitted: auto-generated
- References: <bug-49896-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
--- Comment #2 from Matthieu Imbert <matthieu.imbert@ens-lyon.fr> 2011-07-29 10:37:33 UTC ---
(In reply to comment #1)
> You lack a definition of test<C>::version.
C++ standard section 9.4.2 states:
If a 'static' data member is of 'const' integral or 'const' enumeral type,
its declaration in the class definition can specify a 'constant-initializer'
which shall be an integral constant expression (5.19). In that case, the
member can appear in integral constant expressions. The member shall still
be defined in a namespace scope if it is used in the program and the
namespace scope definition shall not contain an 'initializer'.
The notion of "used" is defined in section 3.2:
An object or non-overloaded function whose name appears as a potentially-
evaluated expression is used unless it is an object that satisfies the
requirements for appearing in a constant expression (5.19 [expr.const]) and
the
lvalue-to-rvalue conversion (4.1 [conv.lval]) is immediately applied.
I am not a C++ expert but various sources (for example: stroustrup C++ faq:
http://www2.research.att.com/~bs/bs_faq2.html#in-class) seem to say that the
code snippet i sent is valid since the address of test<C>::version is not
taken. Stroustrup says: "You can take the address of a static member if (and
only if) it has an out-of-class definition", which i interpret as: no need for
a definition if address not taken.
So in brief, i think there is no need to define test<C>::version to be correct.