<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 535</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="535"></A><H4>535.
  
Copy construction without a copy constructor
</H4>
<B>Section: </B>11.4.5.3&#160; [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Mike Miller
 &#160;&#160;&#160;

 <B>Date: </B>7 October 2005<BR>


<P>[Voted into the WP at the February, 2012 meeting;
moved to DR at the October, 2012 meeting.]</P>

<P>Footnote 112 (11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#2">class.copy.ctor</A>] paragraph 2) says,</P>

<BLOCKQUOTE>

Because a template constructor is never a copy constructor, the
presence of such a template does not suppress the implicit declaration
of a copy constructor. Template constructors participate in overload
resolution with other constructors, including copy constructors, and a
template constructor may be used to copy an object if it provides a
better match than other constructors.

</BLOCKQUOTE>

<P>However, many of the stipulations about copy construction are
phrased to refer only to &#8220;copy constructors.&#8221;  For
example, 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#14">class.copy.ctor</A>] paragraph 14 says,</P>

<BLOCKQUOTE>

A program is ill-formed if the copy constructor...
for an object is implicitly used and the special member
function is not accessible (11.8 [<A href="https://wg21.link/class.access">class.access</A>]).

</BLOCKQUOTE>

<P>Does that mean that using an inaccessible template constructor
to copy an object is permissible, because it is not a &#8220;copy
constructor?&#8221;  Obviously not, but each use of the term
&#8220;copy constructor&#8221; in the Standard should be examined
to determine if it applies strictly to copy constructors or to
any constructor used for copying.  (A similar issue applies to
&#8220;copy assignment operators,&#8221; which have the same
relationship to assignment operator function templates.)</P>

<P><B>Proposed Resolution (August, 2011):</B></P>

<OL>
<LI><P>Change 6.3 [<A href="https://wg21.link/basic.def.odr#2">basic.def.odr</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

...[<I>Note:</I> This covers calls to named functions (7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>]), operator overloading (Clause 12 [<A href="https://wg21.link/over">over</A>]),
user-defined conversions (11.4.8.3 [<A href="https://wg21.link/class.conv.fct">class.conv.fct</A>]), allocation
function for placement new (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]), as well as
non-default initialization (9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]).  A <DEL>copy
constructor or move</DEL> constructor <INS>selected to copy or move an
object of class type</INS> is odr-used even if the call is actually
elided by the implementation <INS>(11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>])</INS>. &#8212;<I>end note</I>] ...  <DEL>A
copy-assignment function for a class</DEL> <INS>An assignment operator
function in a class</INS> is odr-used by an implicitly-defined
copy-assignment <INS>or move-assignment</INS> function for another
class as specified in 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]. <DEL>A move-assignment
function for a class is odr-used by an implicitly-defined
move-assignment function for another class as specified in
11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>].</DEL> A default constructor...

</BLOCKQUOTE>

<LI><P>Delete 11.4.5 [<A href="https://wg21.link/class.ctor#9">class.ctor</A>] paragraph 9:</P></LI>

<BLOCKQUOTE>

<P><DEL>A copy constructor (11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]) is used to copy
objects of class type.  A move constructor (11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>])
is used to move the contents of objects of class type.</DEL></P>

</BLOCKQUOTE>

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

<BLOCKQUOTE>

...[<I>Note:</I> <DEL>even if there is no call to the destructor or
copy/move constructor, all the semantic restrictions, such as
accessibility (11.8 [<A href="https://wg21.link/class.access">class.access</A>]) and whether the
function is deleted (9.6.3 [<A href="https://wg21.link/dcl.fct.def.delete">dcl.fct.def.delete</A>]), shall be
satisfied.</DEL> <INS>this includes accessibility (11.8 [<A href="https://wg21.link/class.access">class.access</A>]) and whether it is deleted, for the constructor selected
and for the destructor.</INS> However, in the special case of a
function call...

</BLOCKQUOTE>

<LI><P>Change 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#13">class.copy.ctor</A>] paragraph 13 as follows:</P></LI>

<BLOCKQUOTE>

A copy/move constructor that is defaulted and not defined as deleted
is implicitly defined if it is odr-used (6.3 [<A href="https://wg21.link/basic.def.odr">basic.def.odr</A>])
<DEL>to initialize an object of its class type from a copy of an
object of its class type or of a class type derived from its class
type [<I>Footnote:</I> See 9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>] for more details
on direct and copy initialization. &#8212;<I>end footnote</I>]</DEL>
or when it is explicitly defaulted...

</BLOCKQUOTE>

<P><LI>Change 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#31">class.copy.ctor</A>] paragraph 31 as follows:</LI></P>

<BLOCKQUOTE>

When certain criteria are met, an implementation is allowed to omit
the copy/move construction of a class object, even if the
<DEL>copy/move</DEL> constructor <INS>selected for the copy/move
operation</INS> and/or <INS>the</INS> destructor for the object have
side effects...

</BLOCKQUOTE>

<LI><P>Change 12.2.4.2.3 [<A href="https://wg21.link/over.ics.user#4">over.ics.user</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

A conversion of an expression of class type to the same class type is
given Exact Match rank, and a conversion of an expression of class
type to a base class of that type is given Conversion rank, in spite
of the fact that a <DEL>copy/move</DEL> constructor (i.e., a
user-defined conversion function) is called for those cases.

</BLOCKQUOTE>

<LI><P>Change 14.2 [<A href="https://wg21.link/except.throw#3">except.throw</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

A <I>throw-expression</I> <INS>copy-</INS>initializes
<INS>(9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>])</INS> a temporary object, called the
<I>exception object</I>...

</BLOCKQUOTE>

<LI><P>Change 14.2 [<A href="https://wg21.link/except.throw#5">except.throw</A>] paragraph 5 as follows:</P></LI>

<BLOCKQUOTE>

When the thrown object is a class object, the <DEL>copy/move</DEL>
constructor <INS>selected for the copy-initialization</INS> and the
destructor shall be accessible, even if the copy/move operation is
elided (11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]).

</BLOCKQUOTE>

</OL>

<P><I>[Drafting note: 7.6.19 [<A href="https://wg21.link/expr.assign#4">expr.assign</A>] paragraph 4,
Clause 11 [<A href="https://wg21.link/class#4">class</A>] paragraph 4, 11.5 [<A href="https://wg21.link/class.union">class.union</A>] paragraph
1, 6.8.7 [<A href="https://wg21.link/class.temporary#2">class.temporary</A>] paragraph 2, 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]
paragraphs 1-2, and 14.5 [<A href="https://wg21.link/except.spec#14">except.spec</A>] paragraph 14 do not
require any changes.]</I></P>

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