<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1322: Explicit CopyConstructible requirements are insufficient</title>
<meta property="og:title" content="Issue 1322: Explicit CopyConstructible requirements are insufficient">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1322.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="1322"><a href="lwg-defects.html#1322">1322</a>. Explicit <code>CopyConstructible</code> requirements are insufficient</h3>
<p><b>Section:</b> 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2010-02-16 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#utility.arg.requirements">active issues</a> in [utility.arg.requirements].</p>
<p><b>View all other</b> <a href="lwg-index.html#utility.arg.requirements">issues</a> in [utility.arg.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
With the acceptance of library defect <a href="lwg-closed.html#822" title="Object with explicit copy constructor no longer CopyConstructible (Status: NAD)">822</a><sup><a href="https://cplusplus.github.io/LWG/issue822" title="Latest snapshot">(i)</a></sup> only
direct-initialization is supported, and not copy-initialization in the
requirement sets <code>MoveConstructible</code> and <code>CopyConstructible</code>. This
is usually a good thing, if only the library implementation needs to obey these
restrictions, but the Empire strikes back quickly:
</p>

<ol>
<li>
<p>
<em>Affects user-code</em>: <code>std::exception_ptr</code> is defined purely via
requirements, among them <code>CopyConstructible</code>. A strict reading of the
standard would make implementations conforming where <code>std::exception_ptr</code>
has an explicit copy-c'tor and user-code must code defensively. This is a very
unwanted effect for such an important component like
<code>std::exception_ptr</code>.
</p>
</li>

<li>
<p>
<em>Wrong re-use</em>: Recently proposed requirement sets
(<code>NullablePointer</code> as of
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3025.html">N3025</a>,
Hash) or cleanup of existing requirement sets (e.g. iterator requirements as of
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3046.html">N3046</a>)
tend to reuse existing requirement sets, so reusing <code>CopyConstructible</code>
is attempting, even in cases, where the intend is to support copy-initialization
as well.
</p>
</li>

<li>
<p>
<em>Inconsistency</em>: The current iterator requirements set Table 102 (output
iterator requirements) and Table 103 (forward iterator requirements) demonstrate
quite clearly a strong divergence of copy-semantics: The specified semantics of
</p>

<blockquote><pre>
X u(a);
X u = a;
</pre></blockquote>

<p>
are underspecified compared to the most recent clarifications of the
<code>CopyConstructible</code> requirements, c.f. issue <a href="lwg-defects.html#1309" title="Missing expressions for Move/CopyConstructible (Status: C++11)">1309</a><sup><a href="https://cplusplus.github.io/LWG/issue1309" title="Latest snapshot">(i)</a></sup> which is
very unsatisfactory. This will become worse for each further issue that involves
the <code>CopyConstructible</code> specification (for possible directions see <a href="lwg-closed.html#1173" title="&quot;Equivalence&quot; wishy-washiness (Status: NAD)">1173</a><sup><a href="https://cplusplus.github.io/LWG/issue1173" title="Latest snapshot">(i)</a></sup>).
</p>
</li>
</ol>

<p>
The suggested resolution is to define two further requirements
<code>implicit-MoveConstructible</code> and <code>implicit-CopyConstructible</code> (or
any other reasonable name like <code>MoveConvertible</code> and
<code>CopyConvertible</code>) each with a very succinct but precise meaning solving
all three problems mentioned above.
</p>

<p><i>[Batavia: Resolved by accepting <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3215.htm">n3215</a>.]</i></p>







<p id="res-1322"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
Add the following new table ?? after Table 34 &mdash; <code>MoveConstructible</code>
requirements [moveconstructible]:
</p>

<blockquote>

<table border="1">
<caption><ins>Table ?? &mdash; <code>Implicit MoveConstructible</code> requirements
[implicit.moveconstructible] (in addition to
<code>MoveConstructible</code>)</ins></caption>

<tr>
<th><ins>Expression</ins></th>
<th><ins>Operational Semantics</ins></th>
</tr>

<tr>
<td><ins><code>T u = rv;</code></ins></td>
<td><ins>Equivalent to: <code>T u(rv);</code></ins></td>
</tr>

</table>
</blockquote>

</li>

<li>
<p>
Add the following new table ?? after Table 35 &mdash; <code>CopyConstructible</code>
requirements [copyconstructible]:
</p>

<blockquote>

<table border="1">
<caption><ins>Table ?? &mdash; <code>Implicit CopyConstructible</code> requirements
[implicit.copyconstructible] (in addition to
<code>CopyConstructible</code>)</ins></caption>

<tr>
<th><ins>Expression</ins></th>
<th><ins>Operational Semantics</ins></th>
</tr>

<tr>
<td><ins><code>T u = v;</code></ins></td>
<td><ins>Equivalent to: <code>T u(v);</code></ins></td>
</tr>

</table>
</blockquote>

</li>

<li>
<p>
Change 16.4.4.4 <a href="https://wg21.link/nullablepointer.requirements">[nullablepointer.requirements]</a>/1 as follows:
</p>

<blockquote>
<p>
A <code>NullablePointer</code> type is a pointer-like type that supports null
values. A type <code>P</code> meets the requirements of <code>NullablePointer</code> if:
</p>

<ul>
<li>
<code>P</code> satisfies the requirements of <code>EqualityComparable</code>,
<code>DefaultConstructible</code>, <code><ins>implicit</ins> CopyConstructible</code>,
<code>CopyAssignable</code>, and <code>Destructible</code>,
</li>

<li>[..]</li>
</ul>
</blockquote>
</li>

<li>
<p>
Change 16.4.4.5 <a href="https://wg21.link/hash.requirements">[hash.requirements]</a>/1 as indicated: <i>[explicit
copy-constructible functors could not be provided as arguments
to any algorithm that takes these by value. Also a typo is fixed.]</i>
</p>

<blockquote>
<p>
1 A type <code>H</code> meets the <i>Hash</i> requirements if:
</p>
<ul>
<li>
it is a function object type (20.8),
</li>
<li>
it satis<ins>fies</ins><del>ifes</del> the requirements of
<code><ins>implicit</ins> CopyConstructible</code> and <code>Destructible</code>
(20.2.1),
</li>
<li>
[..]
</li>
</ul>

</blockquote>

</li>

<li>
<p>
Change 21.3.2 <a href="https://wg21.link/meta.rqmts">[meta.rqmts]</a>/1+2 as indicated:
</p>

<blockquote>
<p>
1 A <i>UnaryTypeTrait</i> describes a property of a type. It shall be a class
template that takes one template type argument and, optionally, additional
arguments that help define the property being described. It shall be
<code>DefaultConstructible</code>, <code><ins>implicit</ins> CopyConstructible</code>,
[..]
</p>

<p>
2 A <code>BinaryTypeTrait</code> describes a relationship between two types. It
shall be a class template that takes two template type arguments and,
optionally, additional arguments that help define the relationship being
described. It shall be <code>DefaultConstructible</code>,
<code><ins>implicit </ins>CopyConstructible</code>, and [..]
</p>

</blockquote>

</li>

<li>
<p>
Change 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>/4 as indicated: <i>[explicit
copy-constructible functors could not be provided as arguments to any algorithm
that takes these by value]</i>
</p>

<blockquote><p>
4 Every call wrapper (20.8.1) shall be <code><ins>implicit</ins>
MoveConstructible</code>. A simple call wrapper is a call wrapper that is
<code><ins>implicit</ins> CopyConstructible</code> and <code>CopyAssignable</code> and
whose copy constructor, move constructor, and assignment operator do not throw
exceptions. [..]
</p></blockquote>
</li>

<li>
<p>
Change 22.10.6 <a href="https://wg21.link/refwrap">[refwrap]</a>/1 as indicated:
</p>

<blockquote><p>
1 <code>reference_wrapper&lt;T&gt;</code> is a<ins>n <code>implicit</code></ins>
<code>CopyConstructible</code> and <code>CopyAssignable</code> wrapper around a
reference to an object or function of type <code>T</code>.
</p></blockquote>
</li>

<li>
<p>
Change 22.10.15.4 <a href="https://wg21.link/func.bind.bind">[func.bind.bind]</a>/5+9 as indicated:
</p>

<blockquote>
<p>
5 <i>Remarks:</i> The return type shall satisfy the requirements of
<code><ins>implicit</ins> MoveConstructible</code>. If all of <code>FD</code> and
<code>TiD</code> satisfy the requirements of <code>CopyConstructible</code>, then the
return type shall satisfy the requirements of <code><ins>implicit</ins>
CopyConstructible</code>. [<i>Note:</i> this implies that all of <code>FD</code> and
<code>TiD</code> are <code>MoveConstructible</code>. &mdash; <i>end note</i>]
</p>

<p>
[..]
</p>

<p>
9 <i>Remarks:</i> The return type shall satisfy the requirements of
<code><ins>implicit</ins> MoveConstructible</code>. If all of <code>FD</code> and
<code>TiD</code> satisfy the requirements of <code>CopyConstructible</code>, then the
return type shall satisfy the requirements of <code><ins>implicit</ins>
CopyConstructible</code>. [<i>Note:</i> this implies that all of <code>FD</code> and
<code>TiD</code> are <code>MoveConstructible</code>. &mdash; <i>end note</i>]
</p>
</blockquote>

</li>

<li>
<p>
Change 22.10.15.5 <a href="https://wg21.link/func.bind.place">[func.bind.place]</a> as indicated:
</p>

<blockquote><p>
1 All placeholder types shall be <code>DefaultConstructible</code> and
<code><ins>implicit</ins> CopyConstructible</code>, and [..]
</p></blockquote>
</li>

<li>
<p>
Change 20.3.1 <a href="https://wg21.link/unique.ptr">[unique.ptr]</a>/5 as indicated:
</p>

<blockquote><p>
5 Each object of a type <code>U</code> instantiated form the <code>unique_ptr</code>
template specified in this subclause has the strict ownership semantics,
specified above, of a unique pointer. In partial satisfaction of these
semantics, each such <code>U</code> is <code><ins>implicit</ins>
MoveConstructible</code> and <code>MoveAssignable</code>, but is not
<code>CopyConstructible</code> nor <code>CopyAssignable</code>. The template parameter
<code>T</code> of <code>unique_ptr</code> may be an incomplete type.
</p></blockquote>
</li>

<li>
<p>
Change 20.3.2.2 <a href="https://wg21.link/util.smartptr.shared">[util.smartptr.shared]</a>/2 as indicated:
</p>

<blockquote><p>
2 Specializations of <code>shared_ptr</code> shall be
<code><ins>implicit</ins> CopyConstructible</code>, <code>CopyAssignable</code>, and
<code>LessThanComparable</code>, [..]
</p></blockquote>
</li>

<li>
<p>
Change 20.3.2.3 <a href="https://wg21.link/util.smartptr.weak">[util.smartptr.weak]</a>/2 as indicated:
</p>

<blockquote><p>
2 Specializations of <code>weak_ptr</code> shall be <code><ins>implicit</ins>
CopyConstructible</code> and <code>CopyAssignable</code>, allowing their use in
standard containers. The template parameter <code>T</code> of <code>weak_ptr</code> may
be an incomplete type.
</p></blockquote>
</li>

<li>
<p>
Change 24.3.5.2 <a href="https://wg21.link/iterator.iterators">[iterator.iterators]</a>/2 as indicated: <i>[This fixes a
defect in the Iterator requirements. None of the usual algorithms accepting
iterators would be usable with iterators with explicit copy-constructors]</i>
</p>

<blockquote>
<p>
2 A type <code>X</code> satisfies the Iterator requirements if:
</p>

<ul>
<li>
<code>X</code> satisfies the <code><ins>implicit</ins> CopyConstructible</code>,
<code>CopyAssignable</code>, and <code>Destructible</code> requirements (20.2.1)
and lvalues of type <code>X</code> are swappable (20.2.2), and [..]
</li>
<li>...</li>
</ul>

</blockquote>

</li>

<li>
<p>
Change 99 [auto.ptr]/3 as indicated:
</p>

<blockquote><p>
3 [..] Instances of <code>auto_ptr</code> meet the requirements of
<code><ins>implicit</ins> MoveConstructible</code> and <code>MoveAssignable</code>, but
do not meet the requirements of <code>CopyConstructible</code> and
<code>CopyAssignable</code>. &mdash; <i>end note</i>]
</p></blockquote>
</li>

</ol>






</body>
</html>
