<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2358: Apparently-bogus definition of is_empty type trait</title>
<meta property="og:title" content="Issue 2358: Apparently-bogus definition of is_empty type trait">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2358.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#Open">Open</a> status.</em></p>
<h3 id="2358"><a href="lwg-active.html#2358">2358</a>. Apparently-bogus definition of <code>is_empty</code> type trait</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#Open">Open</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2014-02-01 <b>Last modified:</b> 2017-02-02</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#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The 'Condition' for <code>std::is_empty</code> is listed as:
</p>
<blockquote><p>
"<code>T</code> is a class type, but not a union type, with no non-static data members other than bit-fields of length 0, 
no virtual member functions, no virtual base classes, and no base class <code>B</code> for which <code>is_empty&lt;B&gt;::value</code> 
is false."
</p></blockquote>
<p>
This is incorrect: there is no such thing as a non-static data member that is a bit-field of length 0, since bit-fields of 
length 0 must be unnamed, and unnamed bit-fields are not members (see 11.4.10 <a href="https://wg21.link/class.bit">[class.bit]</a> p2).
<p/>
It also means that classes such as:
</p>
<blockquote><pre>
struct S {
 int : 3;
};
</pre></blockquote>
<p>
are empty (because they have no non-static data members). There's implementation divergence on the value of 
<code>is_empty&lt;S&gt;::value</code>.
<p/>
I'm not sure what the purpose of <code>is_empty</code> is (or how it could be useful), but if it's desirable for the above type to 
not be treated as empty, something like this could work:
</p>
<blockquote><p>
"<code>T</code> is a class type, but not a union type, with no non-static data members <del>other than</del><ins>, no unnamed</ins> 
bit-fields of <ins>non-zero</ins> length <del>0</del>, no virtual member functions, no virtual base classes, and no base class 
<code>B</code> for which <code>is_empty&lt;B&gt;::value</code> is false."
</p></blockquote>
<p>
and if the above type <em>should</em> be treated as empty, then this might be appropriate:
</p>
<blockquote><p>
"<code>T</code> is a class type, but not a union type, with no <ins>(named)</ins> non-static data members <del>other than bit-fields of 
length 0</del>, no virtual member functions, no virtual base classes, and no base class <code>B</code> for which 
<code>is_empty&lt;B&gt;::value</code> is false."
</p></blockquote>

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

<p>Walter says: We want <code>is_empty_v&lt;S&gt;</code> to produce false as a result.  Therefore, we recommend adoption of the first of the issue's suggestions.</p>
<p>Tuesday AM: Moved to Tentatively Ready</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<p><i>[2016-10 by Marshall - this PR incorrectly highlighted changed portions]</i></p>


<blockquote class="note">
<p>Modify Table 38 — Type property predicates for <code>is_empty</code> as follows:</p>
<blockquote><p>
<code>T</code> is a non-union class type with no non-static data members <del>other than</del><ins>, no unnamed</ins> bit-fields of <ins>non-zero</ins> length <del>0</del>, no virtual member functions, no virtual base classes, and no base class <code>B</code> for which <code>is_empty_v&lt;B&gt;</code> is false.</p>
</blockquote>
</blockquote>

<p><i>[2016-10 Telecon]</i></p>

<p>Should probably point at section 1.8 for some of this. Status back to 'Open'</p>


<p id="res-2358"><b>Proposed resolution:</b></p>
<p>Modify Table 38 — Type property predicates for <code>is_empty</code> as follows:</p>
<blockquote><p>
<code>T</code> <del>is a class type, but not a union type,</del><ins>is a non-union class type</ins> with no non-static data members<del> other than</del><ins>, no unnamed</ins> bit-fields of <ins>non-zero</ins> length <del>0</del>, no virtual member functions, no virtual base classes, and no base class <code>B</code> for which <code>is_empty_v&lt;B&gt;</code> is false.</p>
</blockquote>





</body>
</html>
