<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2015: Incorrect pre-conditions for some type traits</title>
<meta property="og:title" content="Issue 2015: Incorrect pre-conditions for some type traits">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2015.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++14">C++14</a> status.</em></p>
<h3 id="2015"><a href="lwg-defects.html#2015">2015</a>. Incorrect pre-conditions for some type traits</h3>
<p><b>Section:</b> 21.3.6 <a href="https://wg21.link/meta.unary">[meta.unary]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Nikolay Ivchenkov <b>Opened:</b> 2010-11-08 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.unary">issues</a> in [meta.unary].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>
<p>According to N3126&nbsp;&#x2011;&nbsp;3.9/9,</p>

<p>&quot;Scalar types, trivial class types (Clause 9), arrays of such types
and <i>cv</i>&#x2011;qualified versions of these types (3.9.3) are collectively
called <i>trivial types</i>.&quot;</p>

<p>Thus, an array (possibly of unknown bound) can be trivial type, non&#x2011;trivial type, 
or an array type whose triviality cannot be determined because its element type is incomplete.</p>

<p>According to N3126&nbsp;&#x2011;&nbsp;Table 45, preconditions for <code>std::is_trivial</code> are
defined as follows:</p>

<p>&quot;<code>T</code> shall be a complete type, (possibly <i>cv</i>-qualified) <code>void</code>, 
or an array of unknown bound&quot;</p>

<p>It seems that &quot;an array of unknown bound&quot; should be changed to &quot;an
array of unknown bound of a complete element type&quot;. Preconditions for
some other templates (e.g., <code>std::is_trivially_copyable</code>,
<code>std::is_standard_layout</code>, <code>std::is_pod</code>, and <code>std::is_literal_type</code>) should
be changed similarly.</p>

<p>On the other hand, some preconditions look too restrictive. For
example, <code>std::is_empty</code> and <code>std::is_polymorphic</code> might accept any
incomplete non&#x2011;class type.</p>

<p><i>[2011-02-18: Daniel provides wording proposal]</i></p>


<p>
While reviewing the individual preconditions I could find three different groups of
either too weakening or too strengthening constraints:
</p>
<ol>
<li><pre>is_empty/is_polymorphic/is_abstract/has_virtual_destructor:</pre>

<p>These traits can only apply for <em>non&#x2011;union class types</em>, otherwise the result must
always be false</p>
</li>

<li><pre>is_base_of:</pre>

<p>Similar to the previous bullet, but the current wording comes already near to that ideal,
it only misses to add the <em>non&#x2011;union</em> aspect.</p>
</li>

<li><pre>is_trivial/is_trivially_copyable/is_standard_layout/is_pod/is_literal_type:</pre>

<p>These traits always require that <code>std::remove_all_extents&lt;T&gt;::type</code> to be <code><i>cv</i> void</code> or 
a complete type.</p>
</li>
</ol>

<p><i>[Bloomington, 2011]</i></p>

<p>
Move to Ready
</p>



<p id="res-2015"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
Modify the pre-conditions of the following type traits in 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a>, Table 48 &mdash; Type property predicates:
</p>

<blockquote>
<table border="1">
<caption>Table 48 &mdash; Type property predicates</caption>
<tr>
<th>Template</th>
<th>Condition</th>
<th>Preconditions</th>
</tr>

<tr>
<td colspan="3" style="text-align:center;">...</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_trivial;</code></td>
<td><code>T</code> is a trivial type (3.9)</td>
<td><code><ins>remove_all_extents&lt;</ins>T<ins>&gt;::type</ins></code><br/>
shall be a complete type<del>,</del><ins> or</ins> (possibly<br/>
cv-qualified) <code>void</code><del>, or an array of<br/>
unknown bound</del>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_trivially_copyable;</code></td>
<td><code>T</code> is a trivially copyable<br/>
type (3.9)</td>
<td><code><ins>remove_all_extents&lt;</ins>T<ins>&gt;::type</ins></code><br/>
shall be a complete type<del>,</del><ins> or</ins> (possibly<br/>
cv-qualified) <code>void</code><del>, or an array of<br/>
unknown bound</del>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_standard_layout;</code></td>
<td><code>T</code> is a standard-layout<br/>
type (3.9)</td>
<td><code><ins>remove_all_extents&lt;</ins>T<ins>&gt;::type</ins></code><br/>
shall be a complete type<del>,</del><ins> or</ins> (possibly<br/>
cv-qualified) <code>void</code><del>, or an array of<br/>
unknown bound</del>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_pod;</code></td>
<td><code>T</code> is a POD type (3.9)</td>
<td><code><ins>remove_all_extents&lt;</ins>T<ins>&gt;::type</ins></code><br/>
shall be a complete type<del>,</del><ins> or</ins> (possibly<br/>
cv-qualified) <code>void</code><del>, or an array of<br/>
unknown bound</del>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_literal_type;</code></td>
<td><code>T</code> is a literal type (3.9)</td>
<td><code><ins>remove_all_extents&lt;</ins>T<ins>&gt;::type</ins></code><br/>
shall be a complete type<del>,</del><ins> or</ins> (possibly<br/>
cv-qualified) <code>void</code><del>, or an array of<br/>
unknown bound</del>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_empty;</code></td>
<td><code>T</code> is a class type, but not a<br/>
union type, with no<br/>
non-static data members<br/>
other than bit-fields of<br/>
length 0, no virtual<br/>
member functions, no<br/>
virtual base classes, and<br/>
no base class B for which<br/>
<code>is_empty&lt;B&gt;::value</code> is<br/>
false.</td>
<td><del><code>T</code> shall be a complete type,<br/>
(possibly cv-qualified) <code>void</code>, or<br/>
an array of unknown bound</del><ins>If <code>T</code><br/>
is a non&#x2011;union class type, <code>T</code><br/>
shall be a complete type</ins>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_polymorphic;</code></td>
<td><code>T</code> is a polymorphic<br/>
class (10.3)</td>
<td><del><code>T</code> shall be a complete type,<br/>
type, (possibly cv-qualified) <code>void</code>, or<br/>
an array of unknown bound</del><ins>If <code>T</code><br/>
is a non&#x2011;union class type, <code>T</code><br/>
shall be a complete type</ins>.</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct is_abstract;</code></td>
<td><code>T</code> is an abstract<br/>
class (10.4)</td>
<td><del><code>T</code> shall be a complete type,<br/>
type, (possibly cv-qualified) <code>void</code>, or<br/>
an array of unknown bound</del><ins>If <code>T</code><br/>
is a non&#x2011;union class type, <code>T</code><br/>
shall be a complete type</ins>.</td>
</tr>

<tr>
<td colspan="3" style="text-align:center;">...</td>
</tr>

<tr>
<td><code>template &lt;class T&gt;<br/>
struct has_virtual_destructor;</code></td>
<td><code>T</code> has a virtual<br/>
destructor (12.4)</td>
<td><del><code>T</code> shall be a complete type,<br/>
(possibly cv-qualified) <code>void</code>, or<br/>
an array of unknown bound</del><ins>If <code>T</code><br/>
is a non&#x2011;union class type, <code>T</code><br/>
shall be a complete type</ins>.</td>
</tr>

</table>
</blockquote>

</li>

<li>
<p>
Modify the pre-conditions of the following type traits in 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a>, Table 50 &mdash; Type relationship predicates:
</p>

<blockquote>
<table border="1">
<caption>Table 50 &mdash; Type relationship predicates</caption>
<tr>
<th>Template</th>
<th>Condition</th>
<th>Comments</th>
</tr>

<tr>
<td colspan="3" style="text-align:center;">...</td>
</tr>

<tr>
<td><code>template &lt;class Base, class<br/>
Derived&gt;<br/>
struct is_base_of;</code></td>
<td><code>Base</code> is a base class of<br/>
<code>Derived</code> (10) without<br/>
regard to cv-qualifiers<br/>
or <code>Base</code> and <code>Derived</code><br/>
are not unions and<br/>
name the same class<br/>
type without regard to<br/>
cv-qualifiers</td>
<td>If <code>Base</code> and <code>Derived</code> are<br/>
<ins>non&#x2011;union</ins> class types<br/>
and are different types<br/>
(ignoring possible cv-qualifiers)<br/>
then <code>Derived</code> shall be a complete<br/>
type. [ <i>Note</i>: Base classes that<br/>
are private, protected, or<br/>
ambigious are, nonetheless, base<br/>
classes. &mdash; <i>end note</i> ]</td>
</tr>

<tr>
<td colspan="3" style="text-align:center;">...</td>
</tr>

</table>
</blockquote>
</li>
</ol>





</body>
</html>
