<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2170: Aggregates cannot be DefaultConstructible</title>
<meta property="og:title" content="Issue 2170: Aggregates cannot be DefaultConstructible">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2170.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#C++17">C++17</a> status.</em></p>
<h3 id="2170"><a href="lwg-defects.html#2170">2170</a>. Aggregates cannot be <code>DefaultConstructible</code></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#C++17">C++17</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2012-07-19 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</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#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The lack of the definition of the <code>DefaultConstructible</code> requirements in C++03 was fixed 
by LWG <a href="lwg-defects.html#724" title="DefaultConstructible is not defined (Status: C++11)">724</a><sup><a href="https://cplusplus.github.io/LWG/issue724" title="Latest snapshot">(i)</a></sup> at a time where the core rules of list-initialization were slightly
different than today, at that time value-initialization (shortly) was the primary rule for
class types, i.e. just before applying <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1301">CWG 1301</a>, 
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1324">CWG 1324</a>, and 
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1368">CWG 1368</a>.
<p/>
The order in 9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a> p3 was changed to respect aggregate initialization, but that
had the side-effect that formally aggregate types cannot satisfy the <code>DefaultConstructible</code>
requirements anymore, because we require that
</p>
<blockquote><pre>
T u{};
</pre></blockquote>
<p>
<em>value-initializes</em> the object <code>u</code>.
<p/>
Of-course exclusion of aggregates was not intended, therefore I suggest to extend the requirements
in Table 19 (16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a>) for empty aggregate-initialization as well.
</p>

<p><i>[
2012-10 Portland: Move to Core 
]</i></p>


<p>
We are not qualified to pick apart the Core rules quickly at this point, but the consensus is
that if the core language has changed in this manner, then the fix should similarly be applied
in Core - this is not something that we want users of the language to have to say every time
they want to Value initialize (or aggregate initialize) an object.
</p>

<p>
More to Open until we get a clear response from Core, Alisdair to file an issue with Mike.
</p>

<p><i>[2013-04 Bristol: Back to Library]</i></p>


<p>
The Core Working group opened, discussed, and resolved <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1578">CWG 1578</a>
as NAD for this library-related problem: Empty aggregate initialization and value-initialization are different core language concepts,
and this difference can be observed (e.g. for a type with a deleted default-constructor).
</p>

<p><i>[2014-02-15 Issaquah: Move to Ready]</i></p>

<p>
AM: core says still LWG issue, wording has been non-controversial, move to ready?
</p>
<p>
NJ: what about durations? think they are ok
</p>
<p>
Ville: <code>pair</code> and a few other have value initialize
</p>
<p>
AM: look at core 1578
</p>
<p>
AM: value initialize would require <code>()</code>, remove braces from third row?
</p>
<p>
STL: no
</p>
<p>
PH: core has new issue on aggregates and non-aggregates.
</p>
<p>
AM: right, they said does not affect this issue
</p>
<p>
NJ: why ok with <code>pair</code> and <code>tuple</code>?
</p>
<p>
STL: will use <code>()</code>, <code>tuple</code> of aggregates with deleted constructor is ill-formed
</p>
<p>
Ville: aggregate with reference can't have <code>()</code>
</p>
<p>
STL: <code>{}</code> would be an issue too
</p>
<p>
Ville: aggregate with reference will have <code>()</code> deleted implicitly
</p>
<p>
Move to Ready.
</p>




<p id="res-2170"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3691.</p>

<p>Change Table 19 in 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> as indicated:</p>

<table border="1">
<caption>Table 19 &mdash; <code>DefaultConstructible</code> requirements [defaultconstructible]</caption>

<tr>
<th>Expression</th>
<th>Post-condition</th>
</tr> 

<tr>
<td>
<code>T t;</code>
</td>
<td>
object <code>t</code> is default-initialized
</td>
</tr>

<tr>
<td>
<code>T u{};</code>
</td>
<td>
object <code>u</code> is value-initialized <ins>or aggregate-initialized</ins>
</td>
</tr>

<tr>
<td>
<code>T()</code><br/>
<code>T{}</code>
</td>
<td>
a temporary object of type <code>T</code> is value-initialized <ins>or aggregate-initialized</ins>
</td>
</tr>

</table>






</body>
</html>
