Debian Codegraph @

gcc/testsuite/g++.dg/ext/has_trivial_assign.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& operator=(const B&) { return *this;}
20 };
21
22 struct C
23 {
24 virtual int f() { return 1; }
25 };
26
27 struct D
28 : public B { };
29
30 struct E
31 : public A { };
32
33 struct F
34 {
35 A a;
36 };
37
38 struct G
39 {
40 B b;
41 };
42
43 template<typename T>
44 bool
45 f()
46 { return __has_trivial_assign(T); }
47
48 template<typename T>
49 class My
50 {
51 public:
52 bool
53 f()
54 { return !!__has_trivial_assign(T); }
55 };
56
57 template<typename T>
58 class My2
59 {
60 public:
61 static const bool trait = __has_trivial_assign(T);
62 };
63
64 template<typename T>
65 const bool My2<T>::trait;
66
67 template<typename T, bool b = __has_trivial_assign(T)>
68 struct My3_help
69 { static const bool trait = b; };
70
71 template<typename T, bool b>
72 const bool My3_help<T, b>::trait;
73
74 template<typename T>
75 class My3
76 {
77 public:
78 bool
79 f()
80 { return My3_help<T>::trait; }
81 };
82
83 #define PTEST(T) (__has_trivial_assign(T) && f<T>() \
84 && My<T>().f() && My2<T>::trait && My3<T>().f())
85
86 #define NTEST(T) (!__has_trivial_assign(T) && !f<T>() \
87 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
88
89 int main()
90 {
91 assert (PTEST (int));
92 assert (NTEST (int (int)));
93 assert (NTEST (void));
94 assert (PTEST (A));
95 assert (PTEST (U));
96 assert (NTEST (B));
97 assert (NTEST (C));
98 assert (NTEST (D));
99 assert (PTEST (E));
100 assert (PTEST (E[]));
101 assert (PTEST (F));
102 assert (NTEST (G));
103 assert (NTEST (const A));
104 assert (NTEST (A&));
105
106 return 0;
107 }