For C++17 aggregate bases, we have started adding base fields for empty bases. The code for calculating whether a class is standard layout needs to ignore these.
The C++17 mode diagnostic for direct-enum-init1.C was incorrect. Tested x86_64-pc-linux-gnu, applying to trunk.
commit 9a612cc30d4b3ef905ce45304545d8b99a3cf5b9 Author: Jason Merrill <ja...@redhat.com> Date: Tue May 9 14:15:38 2017 -0400 * class.c (check_bases): Ignore empty bases. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index fc71766..085dbc3 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1860,7 +1860,9 @@ check_bases (tree t, members */ for (basefield = TYPE_FIELDS (basetype); basefield; basefield = DECL_CHAIN (basefield)) - if (TREE_CODE (basefield) == FIELD_DECL) + if (TREE_CODE (basefield) == FIELD_DECL + && DECL_SIZE (basefield) + && !integer_zerop (DECL_SIZE (basefield))) { if (field) CLASSTYPE_NON_STD_LAYOUT (t) = 1; diff --git a/gcc/testsuite/g++.dg/ext/is_std_layout1.C b/gcc/testsuite/g++.dg/ext/is_std_layout1.C new file mode 100644 index 0000000..007c94a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_std_layout1.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++11 } } + +template <int> struct E { }; + +struct E1: E<0>, E<1> { }; +struct E2: E<2>, E<3> { }; + +struct A1x { int n; }; +struct D2: A1x, E1, E2 { }; + +#define SA(X) static_assert((X),#X) +SA(__is_standard_layout (D2)); commit 90bdd7df4aa641d53edacd20414d724babfe4af8 Author: Jason Merrill <ja...@redhat.com> Date: Tue May 9 13:51:07 2017 -0400 * g++.dg/cpp1z/direct-enum-init1.C: Correct error message. diff --git a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C index a17473f..11269cc 100644 --- a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C +++ b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C @@ -22,7 +22,7 @@ foo () C c1 { s }; D d1 { D(t) }; // { dg-error "invalid cast from type 'T' to type 'D {enum}'" } D d2 { t }; // { dg-error "cannot convert 'T' to 'D {enum}' in initialization" "" { target c++14_down } } - // { dg-error "invalid cast from type 'T' to type 'D'" "" { target c++1z } .-1 } + // { dg-error "invalid cast from type 'T' to type 'D {enum}'" "" { target c++1z } .-1 } D d3 { 9 }; // { dg-error "cannot convert 'int' to 'D {enum}' in initialization" "" { target c++14_down } } D d4 { l }; // { dg-error "cannot convert 'long int' to 'D {enum}' in initialization" "" { target c++14_down } } D d5 { D(l) }; @@ -89,7 +89,7 @@ foo2 () C c1 { s }; D d1 { D(t) }; // { dg-error "invalid cast from type 'T' to type 'D {enum}'" } D d2 { t }; // { dg-error "cannot convert 'T' to 'D {enum}' in initialization" "" { target c++14_down } } - // { dg-error "invalid cast from type 'T' to type 'D'" "" { target c++1z } .-1 } + // { dg-error "invalid cast from type 'T' to type 'D {enum}'" "" { target c++1z } .-1 } D d3 { 9 }; // { dg-error "cannot convert 'int' to 'D {enum}' in initialization" "" { target c++14_down } } D d4 { l }; // { dg-error "cannot convert 'long int' to 'D {enum}' in initialization" "" { target c++14_down } } D d5 { D(l) };