<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3440: Aggregate-paren-init breaks direct-initializing a tuple or optional from {aggregate-member-value}</title>
<meta property="og:title" content="Issue 3440: Aggregate-paren-init breaks direct-initializing a tuple or optional from {aggregate-member-value}">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3440.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#NAD">NAD</a> status.</em></p>
<h3 id="3440"><a href="lwg-closed.html#3440">3440</a>. Aggregate-paren-init breaks direct-initializing a <code>tuple</code> or <code>optional</code> from <code>{<i>aggregate-member-value</i>}</code></h3>
<p><b>Section:</b> 22.4.4.2 <a href="https://wg21.link/tuple.cnstr">[tuple.cnstr]</a>, 22.5.3.2 <a href="https://wg21.link/optional.ctor">[optional.ctor]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Ville Voutilainen <b>Opened:</b> 2020-05-01 <b>Last modified:</b> 2020-11-09</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#tuple.cnstr">active issues</a> in [tuple.cnstr].</p>
<p><b>View all other</b> <a href="lwg-index.html#tuple.cnstr">issues</a> in [tuple.cnstr].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
For reference, see <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94890">this gcc bug report</a>.
<p/>
Constructing a <code>tuple</code> or <code>optional</code> from an element value of an aggregate
is broken in C++20. <code>tuple&lt;c&gt; t({val});</code> and <code>optional&lt;c&gt; t({val});</code>
invoked a non-forwarding constructor before, but now the perfect-forwarding converting
constructors are a match, because the element is constructible from <code>{val}</code>. But
it's not convertible, so overload resolution chooses the explicit constructor, and the
initialization fails.
<p/>
Tim Song explains the overload resolution in <a href="https://lists.isocpp.org/lib/2020/05/16131.php">
this reflector discussion</a>.
<p/>
Now that we understand that C++17 called the non-forwarding conversion constructor,
and C++20 tries to use the forwarding conversion constructor, we have the solution.
SFINAE away the forwarding conversion constructor when it would convert an aggregate.
<p/>
This also means that <code>tuple&lt;c&gt; t(0);</code> won't work, which is unfortunate
because <code>tuple&lt;c&gt;/optional&lt;c&gt;</code> no longer mirrors what <code>c</code> can do.
That's okay; in this LWG issue, we first restore feature parity with C++17, and later,
as an extension, enable such initializations so that <code>tuple</code>/<code>optional</code>
mirrors what <code>c</code> can do in C++20.
<p/>
The proposed wording below has been implemented and tested.
</p>

<p><i>[2020-05-09; Reflector prioritization]</i></p>

<p>
Set priority to 2 after reflector discussions.
</p>

<p><i>[2020-06-11; LWG Telecon: Status changed: New &rarr; LEWG.]</i></p>

<p>
Ask LEWG if it's desirable to make <code>({val})</code> work again.
Tomasz would prefer it to be explicit e.g. via <code>std::in_place</code>.
</p>

<p><i>[2020-06-23; LEWG Telecon]</i></p>

<p>
POLL: Make <code>({val})</code> work again, at the risk of non-transparency of tuple constructors and further complicating 
the tuple and optional overload set.
</p>
<pre>
SF F N A SA
0  5 6 9 0
</pre>
<p>
No consensus for change. Close as Not a defect.
</p>
<p><i>[2020-11-09 Status changed: Tentatively NAD &rarr; NAD.]</i></p>



<p id="res-3440"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.</p>

<ol>
<li><p>Modify 22.4.4.2 <a href="https://wg21.link/tuple.cnstr">[tuple.cnstr]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class... UTypes&gt; constexpr explicit(<i>see below</i>) tuple(UTypes&amp;&amp;... u);
</pre>
<blockquote>
<p>
-11- <i>Constraints:</i> <code>sizeof...(Types)</code> equals <code>sizeof...(UTypes)</code> and
<code>sizeof...(Types) &ge; 1</code> and <code>is_constructible_v&lt;T<sub><i>i</i></sub>, U<sub><i>i</i></sub>&gt;</code>
is <code>true</code> for all <code><i>i</i></code> <ins>and <code>conjunction_v&lt;is_aggregate&lt;remove_reference_t&lt;T<sub><i>i</i></sub>&gt;&gt;,
negation&lt;is_same&lt;remove_reference_t&lt;T<sub><i>i</i></sub>&gt;, remove_reference_t&lt;U<sub><i>i</i></sub>&gt;&gt;&gt;&gt;</code> is
<code>false</code> for all <code><i>i</i></code></ins>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 22.5.3.2 <a href="https://wg21.link/optional.ctor">[optional.ctor]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class U = T&gt; constexpr explicit(<i>see below</i>) optional(U&amp;&amp; v);
</pre>
<blockquote>
<p>
-22- <i>Constraints:</i> <code>is_constructible_v&lt;T, U&gt;</code> is <code>true</code>,
<code>is_same_v&lt;remove_cvref_t&lt;U&gt;, in_place_t&gt;</code> is <code>false</code>, <del>and</del>
<code>is_same_v&lt;remove_cvref_t&lt;U&gt;, optional&gt;</code> is <code>false</code><ins>, and
<code>conjunction_v&lt;is_aggregate&lt;T&gt;, negation&lt;is_same&lt;T,
remove_reference_t&lt;U&gt;&gt;&gt;&gt;</code> is <code>false</code></ins>.
</p>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
