summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/std-layout1.C
blob: bdad8211145ef121960fa8ce00ec30c2eb53b480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// { dg-options "-std=c++0x" }

// [basic.types]/10:
// Scalar types, standard-layout class types (Clause 9), arrays of such
// types and cv-qualified versions of these types (3.9.3) are collectively
// called standard-layout types.

// [class]/7:
// A standard-layout class is a class that:
// * has no non-static data members of type non-standard-layout class (or
// array of such types) or reference,
// * has no virtual functions (10.3) and no virtual base classes (10.1),
// * has the same access control (Clause 11) for all non-static data members,
// * has no non-standard-layout base classes,
// * 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, and
// * has no base classes of the same type as the first non-static data member.

#include <type_traits>

#define TRY(expr) static_assert (expr, #expr)
#define YES(type) TRY(std::is_standard_layout<type>::value); \
  TRY(std::is_standard_layout<type[]>::value); \
  TRY(std::is_standard_layout<const volatile type>::value);
#define NO(type) TRY(!std::is_standard_layout<type>::value); \
  TRY(!std::is_standard_layout<type[]>::value); \
  TRY(!std::is_standard_layout<const volatile type>::value);
#define NONPOD(type) TRY(!std::is_pod<type>::value); \
  TRY(!std::is_pod<type[]>::value); \
  TRY(!std::is_pod<const volatile type>::value);

struct A;

YES(int);
YES(__complex int);
YES(void *);
YES(int A::*);
typedef int (A::*pmf)();
YES(pmf);

struct A { ~A(); };
YES(A);
NONPOD(A);
struct F: public A { int i; };
YES(F);
NONPOD(F);
struct G: public A { A a; };
NO(G);
struct M { A a; };
YES(M);

class B
{
  int i;
  __complex int c;
  void *p;
  double ar[4];
  int A::* pm;
  int (A::*pmf)();
};
YES(B);
struct D: public B { };
YES(D);
struct E: public B { int q; };
NO(E);
struct D2: public B { };
YES(D2);
struct I: public D, public D2 { };
NO(I);

struct C
{
  int i;
private:
  int j;
};
NO(C);
struct H: public C { };
NO(H);
struct N { C c; };
NO(N);

struct J { virtual void f(); };
struct J2: J { };
NO(J);
NO(J2);
struct K { };
struct L: virtual K {};
YES(K);
NO(L);