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