<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 406</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="406"></A><H4>406.
  
Static data member in class with name for linkage purposes
</H4>
<B>Section: </B>11.4.9.3&#160; [<A href="https://wg21.link/class.static.data">class.static.data</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD1
 &#160;&#160;&#160;

 <B>Submitter: </B>Jorgen Bundgaard
 &#160;&#160;&#160;

 <B>Date: </B>12 Mar 2003<BR>


<P>[Voted into WP at March 2004 meeting.]</P>

<P> 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 [<A href="https://wg21.link/class.static.data#5">class.static.data</A>] paragraph 5.</P>

<PRE>
  struct B {
         typedef struct {
                 static int i;          // Is this legal C++ ?
         } A;
  };

  int B::A::i = 47;      // Is this legal C++ ?
</PRE>

<P> 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 [<A href="https://wg21.link/dcl.typedef#5">dcl.typedef</A>] 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.</P>

<P>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 [<A href="https://wg21.link/class.static.data#5">class.static.data</A>] paragraph 5)
.</P>

<P>Our position is therefore that the above test program is
indeed legal C++. Can you confirm or reject this claim?</P>

<P>
<U>Herb Sutter replied to the submitter as follows:</U>
Here are my notes based on a grep for
"unnamed class" in the standard:</P>
<UL>
<LI>
6.7 [<A href="https://wg21.link/basic.link#4">basic.link</A>] paragraph 4, bullet 3, makes a note that
does not directly speak to your question but which draws the same distinction:
<BLOCKQUOTE>
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 [<A href="https://wg21.link/dcl.typedef">dcl.typedef</A>]);
</BLOCKQUOTE>
Likewise in your example, you have an unnamed class defined in a
typedef declaration.
</LI>
<LI>
11.4.9.3 [<A href="https://wg21.link/class.static.data#5">class.static.data</A>] paragraph 5 does indeed appear to
me to make your example not supported by ISO C++ (although implementations
could allow it as an extension, and many implementation do happen to allow it).
</LI>
<LI>
9.2.4 [<A href="https://wg21.link/dcl.typedef#5">dcl.typedef</A>] paragraph 5 does indeed likewise confirm
the interpretation you give of an unnamed class.
</LI>
</UL>

<P>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 [<A href="https://wg21.link/class#1">class</A>] paragraph 1:</P>

<UL>
<I>class-name</I><TT>:</TT>
<UL>
<I>identifier</I><BR>
    <I>template-id</I>
</UL>
</UL>

<P><B>Notes from the October 2003 meeting:</B></P>

<P>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 [<A href="https://wg21.link/class.static.data#5">class.static.data</A>] paragraph 5 should be corrected
or deleted.</P>

<P><B>Proposed Resolution (October 2003):</B></P>

<P>
At the end of Clause 11 [<A href="https://wg21.link/class">class</A>],
paragraph 1, add the following:</P>

<BLOCKQUOTE>
A <I>class-specifier</I> where the <I>class-head</I> omits
the optional <I>identifier</I> defines an unnamed class.
</BLOCKQUOTE>

<P>
Delete the following from 11.4.9.3 [<A href="https://wg21.link/class.static.data#5">class.static.data</A>] paragraph 5:</P>

<BLOCKQUOTE>
[ <I>Note:</I> this is because there is no mechanism to provide the
definitions for such static data members. ]
</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
