Steps to reproduce: 1. Compile the following code with gcc 6.3.0 (maybe affects other versions, I was not able to check): #include <iostream> #include <type_traits> struct Q {}; struct S : Q {}; struct T : Q {}; struct NonPod : S, T {}; int main(int argc, char** argv) { std::cout << (bool)std::is_pod<NonPod>::value << " "; std::cout << (bool)std::is_standard_layout<NonPod>::value << std::endl; return 0; } 2. Run the result program. Expected result: 0 0 (the NonPod structure is not a standard-layout class as described here: http://en.cppreference.com/w/cpp/concept/StandardLayoutType). Actual result: 1 1
G++ doesn't implement DR 1813 yet, https://wg21.link/cwg1813 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), "" ); int main() { } G++ fails the last assertion (and Clang fails the last two).
*** Bug 91064 has been marked as a duplicate of this bug. ***
Clang 7 and newer now implement DR 1813. I'll take a look.
https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00304.html
Author: mpolacek Date: Fri Jul 5 14:45:30 2019 New Revision: 273139 URL: https://gcc.gnu.org/viewcvs?rev=273139&root=gcc&view=rev Log: 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. Added: trunk/gcc/testsuite/g++.dg/ext/is_std_layout3.C trunk/gcc/testsuite/g++.dg/ext/is_std_layout4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/class.c trunk/gcc/testsuite/ChangeLog
Fixed for GCC 10.
Related PRs: PR91079 PR91080 PR91081