Debian Codegraph @

gcc/testsuite/g++.dg/ext/has_trivial_constructor.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
3 #include <cassert>
4
5 struct A
6 {
7 double a;
8 double b;
9 };
10
11 union U
12 {
13 double a;
14 double b;
15 };
16
17 struct B
18 {
19 B() { }
20 };
21
22 struct C
23 : public B { };
24
25 struct D
26 : public A { };
27
28 struct E
29 {
30 A a;
31 };
32
33 struct F
34 {
35 B b;
36 };
37
38 template<typename T>
39 bool
40 f()
41 { return __has_trivial_constructor(T); }
42
43 template<typename T>
44 class My
45 {
46 public:
47 bool
48 f()
49 { return !!__has_trivial_constructor(T); }
50 };
51
52 template<typename T>
53 class My2
54 {
55 public:
56 static const bool trait = __has_trivial_constructor(T);
57 };
58
59 template<typename T>
60 const bool My2<T>::trait;
61
62 template<typename T, bool b = __has_trivial_constructor(T)>
63 struct My3_help
64 { static const bool trait = b; };
65
66 template<typename T, bool b>
67 const bool My3_help<T, b>::trait;
68
69 template<typename T>
70 class My3
71 {
72 public:
73 bool
74 f()
75 { return My3_help<T>::trait; }
76 };
77
78 #define PTEST(T) (__has_trivial_constructor(T) && f<T>() \
79 && My<T>().f() && My2<T>::trait && My3<T>().f())
80
81 #define NTEST(T) (!__has_trivial_constructor(T) && !f<T>() \
82 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
83
84 int main()
85 {
86 assert (PTEST (int));
87 assert (NTEST (int (int)));
88 assert (NTEST (void));
89 assert (PTEST (A));
90 assert (PTEST (U));
91 assert (NTEST (B));
92 assert (NTEST (C));
93 assert (PTEST (D));
94 assert (PTEST (D[]));
95 assert (PTEST (E));
96 assert (NTEST (F));
97
98 return 0;
99 }