1 // { dg-options "-std=c++0x" } 2 3 // [basic.types]/10: 4 // Scalar types, standard-layout class types (Clause 9), arrays of such 5 // types and cv-qualified versions of these types (3.9.3) are collectively 6 // called standard-layout types. 7 8 // [class]/7: 9 // A standard-layout class is a class that: 10 // * has no non-static data members of type non-standard-layout class (or 11 // array of such types) or reference, 12 // * has no virtual functions (10.3) and no virtual base classes (10.1), 13 // * has the same access control (Clause 11) for all non-static data members, 14 // * has no non-standard-layout base classes, 15 // * either has no non-static data members in the most-derived class and at 16 // most one base class with non-static data members, or has no base classes 17 // with non-static data members, and 18 // * has no base classes of the same type as the first non-static data member. 19 20 #include <type_traits> 21 22 #define TRY(expr) static_assert (expr, #expr) 23 #define YES(type) TRY(std::is_standard_layout<type>::value); \ 24 TRY(std::is_standard_layout<type[]>::value); \ 25 TRY(std::is_standard_layout<const volatile type>::value); 26 #define NO(type) TRY(!std::is_standard_layout<type>::value); \ 27 TRY(!std::is_standard_layout<type[]>::value); \ 28 TRY(!std::is_standard_layout<const volatile type>::value); 29 #define NONPOD(type) TRY(!std::is_pod<type>::value); \ 30 TRY(!std::is_pod<type[]>::value); \ 31 TRY(!std::is_pod<const volatile type>::value); 32 33 struct A; 34 35 YES(int); 36 YES(__complex int); 37 YES(void *); 38 YES(int A::*); 39 typedef int (A::*pmf)(); 40 YES(pmf); 41 42 struct A { ~A(); }; 43 YES(A); 44 NONPOD(A); 45 struct F: public A { int i; }; 46 YES(F); 47 NONPOD(F); 48 struct G: public A { A a; }; 49 NO(G); 50 struct M { A a; }; 51 YES(M); 52 53 class B 54 { 55 int i; 56 __complex int c; 57 void *p; 58 double ar[4]; 59 int A::* pm; 60 int (A::*pmf)(); 61 }; 62 YES(B); 63 struct D: public B { }; 64 YES(D); 65 struct E: public B { int q; }; 66 NO(E); 67 struct D2: public B { }; 68 YES(D2); 69 struct I: public D, public D2 { }; 70 NO(I); 71 72 struct C 73 { 74 int i; 75 private: 76 int j; 77 }; 78 NO(C); 79 struct H: public C { }; 80 NO(H); 81 struct N { C c; }; 82 NO(N); 83 84 struct J { virtual void f(); }; 85 struct J2: J { }; 86 NO(J); 87 NO(J2); 88 struct K { }; 89 struct L: virtual K {}; 90 YES(K); 91 NO(L); 92