Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/trivial1.C

raw
1 // { dg-do compile { target c++11 } }
2 // { dg-additional-options "-Wno-deprecated" { target c++26 } }
3
4 // [basic.types]/10:
5 // Scalar types, trivial class types (Clause 9), arrays of such types and
6 // cv-qualified versions of these types (3.9.3) are collectively called
7 // trivial types.
8
9 // [class]/6:
10 // A trivially copyable class is a class that:
11 // * has no non-trivial copy constructors (12.8),
12 // * has no non-trivial copy assignment operators (13.5.3, 12.8), and
13 // * has a trivial destructor (12.4).
14 // A trivial class is a class that has a trivial default constructor (12.1)
15 // and is trivially copyable.
16
17 #include <type_traits>
18
19 #define TRY(expr) static_assert (expr, #expr)
20 #define YES(type) TRY(std::is_trivial<type>::value); \
21 TRY(std::is_trivial<type[]>::value); \
22 TRY(std::is_trivial<const volatile type>::value)
23 #define NO(type) TRY(!std::is_trivial<type>::value); \
24 TRY(!std::is_trivial<type[]>::value); \
25 TRY(!std::is_trivial<const volatile type>::value)
26
27 struct A;
28
29 YES(int);
30 YES(__complex int);
31 YES(void *);
32 YES(int A::*);
33 typedef int (A::*pmf)();
34 YES(pmf);
35
36 struct A { ~A(); };
37 NO(A);
38 struct F: public A { int i; };
39 NO(F);
40 struct G: public A { A a; };
41 NO(G);
42 struct M { A a; };
43 NO(M);
44
45 class B
46 {
47 int i;
48 __complex int c;
49 void *p;
50 double ar[4];
51 int A::* pm;
52 int (A::*pmf)();
53 };
54 YES(B);
55 struct D: public B { };
56 YES(D);
57 struct E: public B { int q; };
58 YES(E);
59 struct D2: public B { };
60 YES(D2);
61 struct I: public D, public D2 { };
62 YES(I);
63
64 struct C
65 {
66 int i;
67 private:
68 int j;
69 };
70 YES(C);
71 struct H: public C { };
72 YES(H);
73 struct N { C c; };
74 YES(N);
75
76 struct J { virtual void f(); };
77 struct J2: J { };
78 NO(J);
79 NO(J2);
80 struct K { };
81 struct L: virtual K {};
82 YES(K);
83 NO(L);
84
85 // PR c++/41421
86 struct O { O(int); };
87 NO(O);