<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - __is_standard_layout is wrong when a base class is the type of first non-static data member"
href="https://bugs.llvm.org/show_bug.cgi?id=48397">48397</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__is_standard_layout is wrong when a base class is the type of first non-static data member
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>URL</th>
<td>https://wandbox.org/permlink/YHg7sBk5XEY5pz1B
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>k_satoda@f2.dion.ne.jp
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>The static_assert in the following code fails on clang HEAD 12.0.0
(<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
1c19900f9417bd0b832c1cb70863b2439a18647f)
but should succeed as D is not a standard-layout class.
struct B1 {};
struct B2 { B1 b1; };
struct D : B1, B2 {};
static_assert(!__is_standard_layout(D), "D is not a standard-layout class");
Tested at: <a href="https://wandbox.org/permlink/ha8cStNKHEKl2BaJ">https://wandbox.org/permlink/ha8cStNKHEKl2BaJ</a>
The standard says: <a href="https://timsong-cpp.github.io/cppwp/n4659/class#7">https://timsong-cpp.github.io/cppwp/n4659/class#7</a>
<span class="quote">> A class S is a standard-layout class if it:
> - ...
> - has no element of the set M(S) of types (defined below) as a base class.
> M(X) is defined as follows:
> - ...
> - If X is a non-union class type whose first non-static data member
> has type X0 (where said member may be an anonymous union), the
> set M(X) consists of X0 and the elements of M(X0).</span >
The set M(D) consists of just B1 because D is a non-union class type
whose first non-static data member has type B1. Then, because D has B1
as a base class, D is not a standard-layout class.
(If D is a standard-layout class, it must be layout compatible with B2.
But sizeof(D) is 2 while sizeof(B2) is 1, which means they can't be
layout compatible.)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>