<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1734</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="1734"></A><H4>1734.
  
Nontrivial deleted copy functions
</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>CD4
 &#160;&#160;&#160;

 <B>Submitter: </B>James Widman
 &#160;&#160;&#160;

 <B>Date: </B>2013-08-09<BR>


<P>[Adopted at the February, 2016 meeting.]</P>



<P>The intent was for PODs in C++11 to be a superset of C++03 PODs.
Consequently, in the following example, <TT>C</TT> should be a POD
but isn't:</P>

<PRE>
  struct A {
    const int m;
    A&amp; operator=(A const&amp;) = default; //<SPAN CLASS="cmnt"> deleted and trivial, so </SPAN>A<SPAN CLASS="cmnt"> is a</SPAN>
                                      //<SPAN CLASS="cmnt"> POD, as it would be in 2003</SPAN>
                                      //<SPAN CLASS="cmnt"> without this explicit </SPAN>op=<SPAN CLASS="cmnt"> decl</SPAN>
  };
  static_assert(__is_trivially_copyable(A), "");

  struct B {
    int i;
    B&amp; operator=(B &amp;) &amp; = default;      //<SPAN CLASS="cmnt"> non-trivial</SPAN>
    B&amp; operator=(B const&amp;) &amp; = default; //<SPAN CLASS="cmnt"> trivial</SPAN>
  };

  struct C {
    const B m;
    C&amp; operator=(C const&amp; r) = default; //<SPAN CLASS="cmnt"> deleted (apparently), but non-trivial (apparently)</SPAN>
    /*<SPAN CLASS="cmnt"> Notionally:</SPAN>
      C&amp; operator=(C const&amp; r) {
        (*this).m.operator=(r.m);
        return *this;
      }
    */
  };
  static_assert(!__is_trivially_copyable(C), "");
</PRE>

<P>This is because of the following text from 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor#25">class.copy.ctor</A>] paragraph 25:
</P>

<BLOCKQUOTE>

for each non-static data member of <TT>X</TT> that is of class type (or
array thereof), the assignment operator selected to copy/move that member
is trivial;

</BLOCKQUOTE>

<P>In this case, overload resolution fails, so no assignment operator
is selected, so <TT>C::operator=(const C&amp;)</TT> is non-trivial.</P>

<P>(See also <A HREF="1928.html">issue 1928</A>.)</P>

<P><B>Additional note, November, 2014:</B></P>

<P>See paper N4148.</P>

<P><B>Additional note, October, 2015:</B></P>

<P>Moved from "extension" to "open" status, along with
<A HREF="1928.html">issue 1928</A>, to allow reconsideration
by CWG.  It has been suggested that the triviality of a deleted
function should be irrelevant, since it cannot be used in any
event.  A possible change to implement that, more conservative than
the one proposed in N4148, would be:</P>

<BLOCKQUOTE>

<P>A trivially copyable class is a class that:</P>

<UL>
<LI><P>has no non-trivial, non-deleted copy constructors
(11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</P></LI>

<LI><P>has no non-trivial, non-deleted move constructors
(11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</P></LI>

<LI><P>has no non-trivial, non-deleted copy assignment operators
(12.4.3.2 [<A href="https://wg21.link/over.assign">over.assign</A>], 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</P></LI>

<LI><P>has no non-trivial, non-deleted move assignment operators
(12.4.3.2 [<A href="https://wg21.link/over.assign">over.assign</A>], 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</P></LI>

<LI><P>has at least one non-deleted copy or move constructor or
assignment operator, and</P></LI>

<LI><P>has a trivial, non-deleted destructor
(11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]).</P></LI>

</UL>

</BLOCKQUOTE>



<P><B>Proposed resolution (October, 2015):</B></P>

<P>Change Clause 11 [<A href="https://wg21.link/class#6">class</A>] paragraph 6 as follows:</P>

<BLOCKQUOTE>

<P>A <I>trivially copyable class</I> is a class<DEL> that</DEL>:</P>

<UL>
<LI><P><DEL>has no non-trivial copy constructors
(11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</DEL></P></LI>

<LI><P><DEL>has no non-trivial move constructors
(11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</DEL></P></LI>

<LI><P><DEL>has no non-trivial copy assignment operators
(12.4.3.2 [<A href="https://wg21.link/over.assign">over.assign</A>], 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),</DEL></P></LI>

<LI><P><DEL>has no non-trivial move assignment operators
(12.4.3.2 [<A href="https://wg21.link/over.assign">over.assign</A>], 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]),
and</DEL></P></LI>

<LI><P><INS>where each copy constructor, move constructor, copy
assignment operator, and move assignment operator
(11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>], 12.4.3.2 [<A href="https://wg21.link/over.assign">over.assign</A>]) is
either deleted or trivial,</INS></P></LI>

<LI><P><INS>that has at least one non-deleted copy constructor,
move constructor, copy assignment operator, or move
assignment operator, and</INS></P></LI>

<LI><P>
<INS>that</INS> has a trivial<INS>, non-deleted</INS>
destructor (11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]).</P></LI>

</UL>

</BLOCKQUOTE>

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