Debian Codegraph @

gcc/testsuite/g++.dg/ext/has_trivial_destructor-1.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 template<typename T>
29 bool
30 f()
31 { return __has_trivial_destructor(T); }
32
33 template<typename T>
34 class My
35 {
36 public:
37 bool
38 f()
39 { return !!__has_trivial_destructor(T); }
40 };
41
42 template<typename T>
43 class My2
44 {
45 public:
46 static const bool trait = __has_trivial_destructor(T);
47 };
48
49 template<typename T>
50 const bool My2<T>::trait;
51
52 template<typename T, bool b = __has_trivial_destructor(T)>
53 struct My3_help
54 { static const bool trait = b; };
55
56 template<typename T, bool b>
57 const bool My3_help<T, b>::trait;
58
59 template<typename T>
60 class My3
61 {
62 public:
63 bool
64 f()
65 { return My3_help<T>::trait; }
66 };
67
68 #define PTEST(T) (__has_trivial_destructor(T) && f<T>() \
69 && My<T>().f() && My2<T>::trait && My3<T>().f())
70
71 #define NTEST(T) (!__has_trivial_destructor(T) && !f<T>() \
72 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
73
74 int main()
75 {
76 assert (PTEST (int));
77 assert (NTEST (int (int)));
78 assert (NTEST (void));
79 assert (PTEST (A));
80 assert (PTEST (U));
81 assert (NTEST (B));
82 assert (NTEST (C));
83 assert (PTEST (D));
84 assert (PTEST (D[]));
85
86 return 0;
87 }