<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 263</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="263"></A><H4>263.
  
Can a constructor be declared a friend?
</H4>
<B>Section: </B>11.4.5&#160; [<A href="https://wg21.link/class.ctor">class.ctor</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Martin Sebor
 &#160;&#160;&#160;

 <B>Date: </B>13 Nov 2000<BR>


<P>[Voted into WP at April 2003 meeting.]</P>



<P>According to 11.4.5 [<A href="https://wg21.link/class.ctor#1">class.ctor</A>] paragraph 1, a
declaration of a constructor has a special limited syntax, in
which only <I>function-specifier</I>s are allowed.  A <TT>friend</TT>
specifier is not a <I>function-specifier</I>, so one interpretation
is that a constructor cannot be declared in a <TT>friend</TT>
declaration.</P>

<P>(It should also be noted, however, that neither <TT>friend</TT>
nor <I>function-specifier</I> is part of the <INS>declarator</INS>
syntax, so it's not clear that anything conclusive can be derived
from the wording of 11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>].)</P>

<P><B>Notes from 04/01 meeting:</B></P>

<P>The consensus of the core language working group was that it
should be permitted to declare constructors as <TT>friend</TT>s.</P>

<P><B>Proposed Resolution (revised October 2002):</B></P>

<P>Change paragraph 1a in 6.5.5.2 [<A href="https://wg21.link/class.qual">class.qual</A>] (added by
the resolution of issue 147) as follows:</P>
<BLOCKQUOTE>
If the <I>nested-name-specifier</I> nominates a class <TT>C</TT>, and the
name specified after the <I>nested-name-specifier</I>, when looked up in
<TT>C</TT>, is the injected-class-name of <TT>C</TT> (
Clause 11 [<A href="https://wg21.link/class">class</A>]), the name is instead considered to name the
constructor of class <TT>C</TT>. Such a constructor name shall be used
only in the <I>declarator-id</I> of a <DEL>constructor definition</DEL>
<INS>declaration</INS> that <DEL>appears outside of the class definition</DEL>
<INS>names a constructor</INS>....
</BLOCKQUOTE>

<P>Note: the above does not allow qualified names to be used for
in-class declarations; see 9.3.4 [<A href="https://wg21.link/dcl.meaning#1">dcl.meaning</A>] paragraph 1.
Also note that <A HREF="318.html">issue 318</A> updates the
same paragraph.</P>

<P>Change the example in 11.8.4 [<A href="https://wg21.link/class.friend">class.friend</A>], paragraph 4
as follows:</P>
<PRE>
class Y {
  friend char* X::foo(int);
  <INS>friend X::X(char);   // constructors can be friends</INS>
  <INS>friend X::~X();      // destructors can be friends</INS>
  //...
};
</PRE>

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