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

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

 <B>Submitter: </B>Faisal Vali
 &#160;&#160;&#160;

 <B>Date: </B>2016-03-02<BR>


<P>[Accepted at the March, 2018 (Jacksonville) meeting.]</P>



<P>Bullet 1.2 of 11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>], describing declarator forms
that are considered to declare a constructor, says:</P>

<BLOCKQUOTE>

<P>...and the <I>id-expression</I> has one of the following forms:</P>

<UL>
<LI><P>...</P></LI>

<LI><P>in a <I>member-declaration</I> that belongs to
the <I>member-specification</I> of a class template but is not a friend
declaration, the <I>id-expression</I> is a <I>class-name</I> that names the
current instantiation (13.8.3.2 [<A href="https://wg21.link/temp.dep.type">temp.dep.type</A>]) of the
immediately-enclosing class template; or</P></LI>

<LI><P>...</P></LI>

</UL>

</BLOCKQUOTE>

<P>The term <I>class-name</I> includes <I>simple-template-id</I>. It is
not clear that allowing a constructor declaration of the form</P>

<PRE>
  template&lt;class T&gt; struct X {
    X&lt;T&gt;(T); //<SPAN CLASS="cmnt"> constructor </SPAN>
  };
</PRE>

<P>is useful or helpful.</P>

<P><B>Proposed resolution (November, 2017)</B></P>

<OL>
<LI><P>Change 11.4.5 [<A href="https://wg21.link/class.ctor#1">class.ctor</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

<P>...and the <I>id-expression</I> has one of the following forms:</P>

<UL>
<LI><P>in a <I>member-declaration</I> that belongs to
the <I>member-specification</I> of a class <INS>or class template</INS> but
is not a friend declaration (11.8.4 [<A href="https://wg21.link/class.friend">class.friend</A>]),
the <I>id-expression</I> is the injected-class-name (
Clause 11 [<A href="https://wg21.link/class">class</A>]) of the immediately-enclosing <DEL>class;</DEL>
<INS>entity or</INS>
</P></LI>

<LI><P><DEL>in a <I>member-declaration</I> that belongs to
the <I>member-specification</I> of a class template but is not a friend
declaration, the <I>id-expression</I> is a <I>class-name</I> that names the
current instantiation (13.8.3.2 [<A href="https://wg21.link/temp.dep.type">temp.dep.type</A>]) of the
immediately-enclosing class template; or</DEL></P></LI>

<LI><P>in a declaration at namespace scope or in a friend declaration,
the <I>id-expression</I> is a <I>qualified-id</I> that names a constructor
(6.5.5.2 [<A href="https://wg21.link/class.qual">class.qual</A>]).</P></LI>

</UL>

</BLOCKQUOTE>

<LI><P>Change 11.4.7 [<A href="https://wg21.link/class.dtor#1">class.dtor</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

<P>...and the <I>id-expression</I> has one of the following forms:</P>

<UL>
<LI>

<P>in a <I>member-declaration</I> that belongs to
the <I>member-specification</I> of a class <INS>or class template</INS>
but is not a friend declaration
(11.8.4 [<A href="https://wg21.link/class.friend">class.friend</A>]), the <I>id-expression</I>
is <TT>~</TT><I>class-name</I> and the <I>class-name</I> is the
injected-class-name (Clause 11 [<A href="https://wg21.link/class">class</A>]) of the
immediately-enclosing <DEL>class;</DEL> <INS>entity or</INS>
</P>
</LI>

<LI>

<P><DEL>in a <I>member-declaration</I> that belongs to
the <I>member-specification</I> of a class template but is not a friend
declaration, the <I>id-expression</I> is <TT>~</TT><I>class-name</I> and
the <I>class-name</I> names the current instantiation
(13.8.3.2 [<A href="https://wg21.link/temp.dep.type">temp.dep.type</A>]) of the immediately-enclosing class
template; or</DEL></P>
</LI>

<LI>

<P>in a declaration at namespace scope or in a friend declaration,
the <I>id-expression</I>
is <I>nested-name-specifier</I> <TT>~</TT><I>class-name</I> and
the <I>class-name</I> names the same class as the
<I>nested-name-specifier</I>.</P>
</LI>

</UL>

</BLOCKQUOTE>

<LI><P>Add the following as a new paragraph in
C.3 [<A href="https://wg21.link/diff.cpp17">diff.cpp17</A>]:</P></LI>

<BLOCKQUOTE>

<P><INS>C.5.x Clause 15: Special member functions
[diff.cpp17.special]</INS></P>

<P><INS>Affected subclauses: 11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>],
11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]<BR>
Change: A <I>simple-template-id</I> is no longer valid as the
<I>declarator-id</I> of a constructor or destructor.<BR>
Rationale: Remove potentially error-prone option for redundancy.<BR>
Effect on original feature: Valid C++ 2017 code may fail to compile.</INS></P>

<PRE>
<INS>  template&lt;class T&gt;
  struct A {
    A&lt;T&gt;();  //<SPAN CLASS="cmnt"> error: simple-template-id not allowed for constructor</SPAN>
    A(int);  //<SPAN CLASS="cmnt"> OK, injected-class-name used</SPAN>
    ~A&lt;T&gt;(); //<SPAN CLASS="cmnt"> error: simple-template-id not allowed for destructor</SPAN>
  };</INS>
</PRE>

</BLOCKQUOTE>

</OL>

<P>(Note that this resolution is a change for C++20, NOT a defect report
against C++17 and earlier versions.)</P>

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