<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3228: Surprising variant construction</title>
<meta property="og:title" content="Issue 3228: Surprising variant construction">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3228.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="3228"><a href="lwg-defects.html#3228">3228</a>. Surprising <code>variant</code> construction</h3>
<p><b>Section:</b> 22.6.3.2 <a href="https://wg21.link/variant.ctor">[variant.ctor]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Barry Revzin <b>Opened:</b> 2019-06-25 <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#variant.ctor">active issues</a> in [variant.ctor].</p>
<p><b>View all other</b> <a href="lwg-index.html#variant.ctor">issues</a> in [variant.ctor].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
User mcencora on reddit today posted this example:
</p>
<blockquote><pre>
#include &lt;variant&gt;

struct ConvertibleToBool
{
  constexpr operator bool() const { return true; }
};

static_assert(std::holds_alternative&lt;bool&gt;(std::variant&lt;int, bool&gt;(ConvertibleToBool{})));
</pre></blockquote>
<p>
Before <a href="https://wg21.link/p0608">P0608</a>, the <code>variant</code> holds <code>bool</code>. After P0608,
the <code>variant</code> holds <code>int</code> so the static assertion fires.
<p/>
I don't know what the right answer is between (a) ill-formed (b) hold <code>bool</code> and (c)
hold <code>int</code> is, but I think (a) and (b) are better options than (c).
</p>

<p><i>[2019-07 Issue Prioritization]</i></p>

<p>Priority to 2 after discussion on the reflector.</p>

<p><i>[This is US212; status set to "LEWG" for guidance on desired behavior.]</i></p>


<p><i>[2020-05-28; LEWG issue reviewing]</i></p>

<p>
<a href="https://wg21.link/p1957r2">P1957R2</a> was accepted in Prague as CWG motion 5 and resolves LWG 3228.
</p>
<p><i>[2020-11-09 Resolved for C++20. Status changed: Tentatively Resolved &rarr; Resolved.]</i></p>



<p><b>Rationale:</b></p>
Resolved by <a href="https://wg21.link/p1957r2">P1957R2</a>.


<p id="res-3228"><b>Proposed resolution:</b></p>




</body>
</html>
