[llvm-bugs] [Bug 48397] New: __is_standard_layout is wrong when a base class is the type of first non-static data member
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Dec 4 21:29:40 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48397
Bug ID: 48397
Summary: __is_standard_layout is wrong when a base class is the
type of first non-static data member
Product: clang
Version: trunk
Hardware: PC
URL: https://wandbox.org/permlink/YHg7sBk5XEY5pz1B
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: k_satoda at f2.dion.ne.jp
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
The static_assert in the following code fails on clang HEAD 12.0.0
(https://github.com/llvm/llvm-project.git
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: https://wandbox.org/permlink/ha8cStNKHEKl2BaJ
The standard says: https://timsong-cpp.github.io/cppwp/n4659/class#7
> 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).
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.)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201205/e8085f45/attachment.html>
More information about the llvm-bugs
mailing list