<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2827: is_trivially_constructible and non-trivial destructors</title>
<meta property="og:title" content="Issue 2827: is_trivially_constructible and non-trivial destructors">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2827.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#New">New</a> status.</em></p>
<h3 id="2827"><a href="lwg-active.html#2827">2827</a>. <code>is_trivially_constructible</code> and non-trivial destructors</h3>
<p><b>Section:</b> 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2016-11-17 <b>Last modified:</b> 2023-05-25</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#meta.unary.prop">active issues</a> in [meta.unary.prop].</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.unary.prop">issues</a> in [meta.unary.prop].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<blockquote><pre>
struct S 
{
  ~S(); // non-trivial
};

static_assert(std::is_trivially_constructible&lt;S&gt;::value, "");
</pre></blockquote>
<p>
Should the assert pass? Implementations disagree.
<p/>
Per 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a>'s Table 38, this trait looks at whether the following variable definition is 
known to call no operation that is not trivial:
</p>
<blockquote><pre>
S t(create&lt;Args&gt;()...);
</pre></blockquote>
<p>
... where <code>Args</code> is an empty pack in this case. That variable definition results in a call to the <code>S</code> destructor. 
Should that call be considered by the trait?
</p>

<p><i>[2017-01-27 Telecon]</i></p>

<p>Priority 3</p>
<p>This issue interacts with <a href="lwg-active.html#2116" title="is_nothrow_constructible and destructors (Status: Open)">2116</a><sup><a href="https://cplusplus.github.io/LWG/issue2116" title="Latest snapshot">(i)</a></sup></p>

<p><i>[2020-01-24; Peter Dimov comments]</i></p>

<p>
<code>std::is_trivially_copy_constructible_v&lt;D&gt;</code>, where <code>D</code> is
</p>
<blockquote><pre>
struct D
{
  ~D() {}
};
</pre></blockquote>
<p>
reports <code>false</code>. This is because the definition of
<code>is_trivially_copy_constructible</code> requires the invented variable 
definition <code>T t(declval&lt;Args&gt;()...);</code>, which in our case is 
<code>D t(declval&lt;D&gt;());</code>, to not call any nontrivial operations.
<p/>
This is interpreted by implementations to include the destructor call,
presumably for consistency with <code>is_nothrow_copy_constructible</code>. 
But that's wrong; the copy constructor <em>is</em> trivial.
<p/>
As a consequence, <code>variant&lt;D&gt;</code> also doesn't have a trivial 
copy constructor, which causes (completely unnecessary) inefficiencies 
when said <code>variant</code> is copied.
</p>

<p><i>[2023-05-25; May 2023 mailing]</i></p>

<p>Alisdair provided <a href="https://wg21.link/P2842R0" title=" Destructor Semantics Do Not Affect Constructible Traits">P2842R0</a>.</p>



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





</body>
</html>
