<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 527</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="527"></A><H4>527.
  
Problems with linkage of types
</H4>
<B>Section: </B>6.7&#160; [<A href="https://wg21.link/basic.link">basic.link</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Daveed Vandevoorde
 &#160;&#160;&#160;

 <B>Date: </B>28 July 2005<BR>


<P>[Voted into WP at October, 2009 meeting.]</P>

<P>The resolution of <A HREF="389.html">issue 389</A> makes code
like</P>

<PRE>
    static struct {
        int i;
        int j;
    } X;
</PRE>

<P>ill-formed.  This breaks a lot of code for no apparent reason,
since the name <TT>X</TT> is not known outside the translation
unit in which it appears; there is therefore no danger of collision
and no need to mangle its name.</P>

<P>There has also been recent discussion on the email reflectors as to
whether the restrictions preventing use of types without linkage as
template arguments is needed or not, with the suggestion that a
mechanism like that used to give members of the unnamed namespace
unique names could be used for unnamed and local types.
 See also <A HREF="488.html">issue 488</A>, which would become moot if types without linkage could be
used as template parameters.
</P>

<P><B>Notes from the October, 2005 meeting:</B></P>

<P>The Evolution Working Group is discussing changes that would
address this issue.  CWG will defer consideration until the outcome
of the EWG discussions is clear.</P>

<P><B>Notes from the April, 2006 meeting:</B></P>

<P>The CWG agreed that the restriction in 6.7 [<A href="https://wg21.link/basic.link#8">basic.link</A>] paragraph 8
on use of a type without linkage should apply only to
variables and functions with external linkage, not to variables and
functions with internal linkage (i.e., the example should be
accepted).  This is a separate issue from the question before the EWG
and should be resolved independently.</P>

<P><B>Additional note (April, 2006):</B></P>

<P>Even the restriction of the rule to functions and objects with
external linkage may not be exactly what we want.  Consider an example
like:</P>

<PRE>
    namespace {
        struct { int i; } s;
    }
</PRE>

<P>The variable <TT>s</TT> has external linkage but can't be named
outside its translation unit, so there's again no reason to prohibit
use of a type without linkage in its declaration.</P>

<P><B>Notes from the June, 2008 meeting:</B></P>

<P>Paper N2657, adopted at the June, 2008 meeting, allows local and
unnamed types to be used as template parameters.  That resolution
is narrowly focused, however, and does not address this issue.</P>

<P><B>Proposed resolution (June, 2009):</B></P>

<P>Change 6.7 [<A href="https://wg21.link/basic.link#8">basic.link</A>] paragraph 8 as follows:</P>

<BLOCKQUOTE>

<P>...A type without linkage shall not be used as the type of a
variable or function with <INS>external</INS> linkage, unless</P>

<UL>
<LI><P>the variable or function has <DEL>extern "C"</DEL> <INS>C
language</INS> linkage (9.12 [<A href="https://wg21.link/dcl.link">dcl.link</A>]), or</P></LI>

<LI><P><INS>the variable or function is declared within an
unnamed namespace (9.9.2 [<A href="https://wg21.link/namespace.def">namespace.def</A>]), or</INS></P></LI>

<LI><P>the variable or function is not used (6.3 [<A href="https://wg21.link/basic.def.odr">basic.def.odr</A>])
or is defined in the same translation unit.</P></LI>

</UL>

</BLOCKQUOTE>

<P><I>[Drafting note: the context shown for the preceding resolution
assumes that the resolution for <A HREF="757.html">issue 757</A>
has been applied.]</I></P>

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