This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Voted into WP at March 2004 meeting.]
The following test program is claimed to be a negative C++ test case for "Unnamed classes shall not contain static data members", c.f. ISO/IEC 14882 section 11.4.9.3 [class.static.data] paragraph 5.
struct B { typedef struct { static int i; // Is this legal C++ ? } A; }; int B::A::i = 47; // Is this legal C++ ?
We are not quite sure about what an "unnamed class" is. There is no exact definition in ISO/IEC 14882; the closest we can come to a hint is the wording of section 9.2.4 [dcl.typedef] paragraph 5, where it seems to be understood that a class-specifier with no identifier between "class" and "{" is unnamed. The identifier provided after "}" ( "A" in the test case above) is there for "linkage purposes" only.
To us, class B::A in the test program above seems "named" enough, and there is certainly a mechanism to provide the definition for B::A::i (in contrast to the note in section 11.4.9.3 [class.static.data] paragraph 5) .
Our position is therefore that the above test program is indeed legal C++. Can you confirm or reject this claim?
Herb Sutter replied to the submitter as follows: Here are my notes based on a grep for "unnamed class" in the standard:
a named class (clause class), or an unnamed class defined in a typedef declaration in which the class has the typedef name for linkage purposes (9.2.4 [dcl.typedef]);Likewise in your example, you have an unnamed class defined in a typedef declaration.
So yes, an unnamed class is one where there is no identifier (class name) between the class-key and the {. This is also in harmony with the production for class-name in Clause 11 [class] paragraph 1:
Notes from the October 2003 meeting:
We agree that the example is not valid; this is an unnamed class. We will add wording to define an unnamed class. The note in 11.4.9.3 [class.static.data] paragraph 5 should be corrected or deleted.
Proposed Resolution (October 2003):
At the end of Clause 11 [class], paragraph 1, add the following:
A class-specifier where the class-head omits the optional identifier defines an unnamed class.
Delete the following from 11.4.9.3 [class.static.data] paragraph 5:
[ Note: this is because there is no mechanism to provide the definitions for such static data members. ]