aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-07-05 14:45:30 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-07-05 14:45:30 +0000
commit899a199767a1a94812bed0642eca3da0c96c9355 (patch)
tree7fb69006c6279bfba18f6de72d9f87967861ce4b
parent2bdc7dcbbd2eee4f114c09443933cc37a546dbff (diff)
downloadgcc-899a199767a1a94812bed0642eca3da0c96c9355.zip
gcc-899a199767a1a94812bed0642eca3da0c96c9355.tar.gz
gcc-899a199767a1a94812bed0642eca3da0c96c9355.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/class.c6
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/ext/is_std_layout3.C18
-rw-r--r--gcc/testsuite/g++.dg/ext/is_std_layout4.C11
5 files changed, 48 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c1dfb7c..f24a096 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2019-07-04 Marek Polacek <polacek@redhat.com>
+
+ 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 <ams@codesourcery.com>
* cp-tree.h (cp_omp_emit_unmappable_type_notes): New prototype.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 73291b3..f77b7f4 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 a57c230..98ad880 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2019-07-04 Marek Polacek <polacek@redhat.com>
+
+ 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 <rguenther@suse.de>
* 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 0000000..b0555c8
--- /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 0000000..09c0098
--- /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), "");