<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2736: nullopt_t insufficiently constrained</title>
<meta property="og:title" content="Issue 2736: nullopt_t insufficiently constrained">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2736.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="2736"><a href="lwg-defects.html#2736">2736</a>. <code>nullopt_t</code> insufficiently constrained</h3>
<p><b>Section:</b> 22.5.5 <a href="https://wg21.link/optional.nullopt">[optional.nullopt]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2016-06-17 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#optional.nullopt">issues</a> in [optional.nullopt].</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>
22.5.5 <a href="https://wg21.link/optional.nullopt">[optional.nullopt]</a>/2 requires of <code>nullopt_t</code> that
</p>
<blockquote>
<p>
Type <code>nullopt_t</code> shall not have a default constructor. It shall be a literal type. Constant <code>nullopt</code> shall 
be initialized with an argument of literal type.
</p>
</blockquote>
<p>
This does not appear sufficient to foreclose the following implementation:
</p>
<blockquote>
<pre>
struct nullopt_t 
{
  constexpr nullopt_t(const nullopt_t&amp;) = default;
};

constexpr nullopt_t nullopt(nullopt_t{});
</pre>
</blockquote>
<ul>
<li><code>nullopt_t</code> has no default constructor because it has a user-declared (copy) constructor;</li>
<li><code>nullopt_t</code> has a trivial destructor, is an aggregate, and is a literal type;</li>
<li><code>nullopt</code> has been initialized with an argument of literal type, to wit, <code>nullopt_t</code>.</li>
</ul>
<p>
But such a <code>nullopt_t</code> is still constructible from <code>{}</code> and so still makes <code>opt = {}</code> ambiguous.
</p>

<p><i>[2016-08 Chicago]</i></p>

<p>This is related to LWG <a href="lwg-defects.html#2510" title="Tag types should not be DefaultConstructible (Status: C++17)">2510</a><sup><a href="https://cplusplus.github.io/LWG/issue2510" title="Latest snapshot">(i)</a></sup>.</p>
<p>Monday PM: Ville to provide updated wording</p>
<p>Fri AM: Moved to Tentatively Ready</p>


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

<ol>
<li><p>Edit 22.5.5 <a href="https://wg21.link/optional.nullopt">[optional.nullopt]</a>/2 as indicated:</p>
<blockquote class="note">
<p>
[<i>Drafting note</i>: <code>{}</code> can do one of three things for a class type:
it may be aggregate initialization, it may call a default constructor,
or it may call an initializer-list constructor (see 9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>, 12.2.2.8 <a href="https://wg21.link/over.match.list">[over.match.list]</a>).
The wording below forecloses all three possibilities. &mdash; <i>end drafting note</i>]
</p>
</blockquote>
<blockquote>
<p>
-2- Type <code>nullopt_t</code> shall not have a default constructor <ins>or an initializer-list constructor</ins>. 
It <ins>shall not be an aggregate and</ins> shall be a literal type. Constant <code>nullopt</code> shall 
be initialized with an argument of literal type.
</p>
</blockquote>
</li>
</ol>






</body>
</html>
