From 899a199767a1a94812bed0642eca3da0c96c9355 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 5 Jul 2019 14:45:30 +0000 Subject: [PATCH] DR 1813 PR c++/83374 - __is_standard_layout wrong for a class with repeated bases. DR 1813 PR c++/83374 - __is_standard_layout wrong for a class with repeated bases. * class.c (check_bases): Set CLASSTYPE_NON_STD_LAYOUT for a class if CLASSTYPE_REPEATED_BASE_P is true. * g++.dg/ext/is_std_layout3.C: New test. * g++.dg/ext/is_std_layout4.C: New test. From-SVN: r273139 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/class.c | 6 +++++- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/ext/is_std_layout3.C | 18 ++++++++++++++++++ gcc/testsuite/g++.dg/ext/is_std_layout4.C | 11 +++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_std_layout3.C create mode 100644 gcc/testsuite/g++.dg/ext/is_std_layout4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c1dfb7cee39..f24a096b9e8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-07-04 Marek Polacek + + DR 1813 + PR c++/83374 - __is_standard_layout wrong for a class with repeated bases. + * class.c (check_bases): Set CLASSTYPE_NON_STD_LAYOUT for a class if + CLASSTYPE_REPEATED_BASE_P is true. + 2019-07-04 Andrew Stubbs * cp-tree.h (cp_omp_emit_unmappable_type_notes): New prototype. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 73291b341fe..f77b7f4834b 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1715,11 +1715,15 @@ check_bases (tree t, && (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field), basetype))) CLASSTYPE_NON_STD_LAYOUT (t) = 1; + /* DR 1813: + ...has at most one base class subobject of any given type... */ + else if (CLASSTYPE_REPEATED_BASE_P (t)) + CLASSTYPE_NON_STD_LAYOUT (t) = 1; else /* ...either has no non-static data members in the most-derived class and at most one base class with non-static data members, or has no base classes with non-static data - members */ + members. FIXME This was reworded in DR 1813. */ for (basefield = TYPE_FIELDS (basetype); basefield; basefield = DECL_CHAIN (basefield)) if (TREE_CODE (basefield) == FIELD_DECL diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a57c230d57d..98ad88063c7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-07-04 Marek Polacek + + DR 1813 + PR c++/83374 - __is_standard_layout wrong for a class with repeated bases. + * g++.dg/ext/is_std_layout3.C: New test. + * g++.dg/ext/is_std_layout4.C: New test. + 2019-07-05 Richard Biener * gcc.dg/tree-ssa/ssa-fre-77.c: New testcase. diff --git a/gcc/testsuite/g++.dg/ext/is_std_layout3.C b/gcc/testsuite/g++.dg/ext/is_std_layout3.C new file mode 100644 index 00000000000..b0555c8207b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_std_layout3.C @@ -0,0 +1,18 @@ +// DR 1813 +// PR c++/83374 - __is_standard_layout wrong for a class with repeated bases. +// { dg-do compile { target c++11 } } + +struct B { int i; }; // standard-layout class +struct C : B { }; // standard-layout class +struct D : C { }; // standard-layout class +struct E : D { char : 4; }; // not a standard-layout class +static_assert( __is_standard_layout(B), "" ); +static_assert( __is_standard_layout(C), "" ); +static_assert( __is_standard_layout(D), "" ); +static_assert( ! __is_standard_layout(E), "" ); + +struct Q {}; +struct S : Q { }; +struct T : Q { }; +struct U : S, T { }; // not a standard-layout class +static_assert( ! __is_standard_layout(U), "" ); diff --git a/gcc/testsuite/g++.dg/ext/is_std_layout4.C b/gcc/testsuite/g++.dg/ext/is_std_layout4.C new file mode 100644 index 00000000000..09c0098120d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_std_layout4.C @@ -0,0 +1,11 @@ +// DR 1813 +// PR c++/83374 - __is_standard_layout wrong for a class with repeated bases. +// { dg-do compile { target c++11 } } + +struct R { }; +struct Q { }; +struct S : R { }; +struct T : Q { }; +struct U : S, T { }; +// No repeated base class subobjects. +static_assert(__is_standard_layout(U), ""); -- 2.30.2