Debian Codegraph @

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

raw
1 // { dg-do run { target c++11 } }
2 // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
3 #include <cassert>
4
5 template<typename T>
6 bool
7 f()
8 { return __is_aggregate(T); }
9
10 template<typename T>
11 class My
12 {
13 public:
14 bool
15 f()
16 { return !!__is_aggregate(T); }
17 };
18
19 template<typename T>
20 class My2
21 {
22 public:
23 static const bool trait = __is_aggregate(T);
24 };
25
26 template<typename T>
27 const bool My2<T>::trait;
28
29 template<typename T, bool b = __is_aggregate(T)>
30 struct My3_help
31 { static const bool trait = b; };
32
33 template<typename T, bool b>
34 const bool My3_help<T, b>::trait;
35
36 template<typename T>
37 class My3
38 {
39 public:
40 bool
41 f()
42 { return My3_help<T>::trait; }
43 };
44
45 #define PTEST(T) (__is_aggregate(T) && f<T>() \
46 && My<T>().f() && My2<T>::trait && My3<T>().f())
47
48 #define NTEST(T) (!__is_aggregate(T) && !f<T>() \
49 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
50
51 struct A { int a, b, c; };
52 class B { static int a; private: static int b; public: int c; };
53 struct C { C () {} int a, b, c; };
54 struct D { explicit D (int) {} int a, b, c; };
55 struct E : public A { int d, e, f; };
56 struct F : public C { using C::C; int d, e, f; };
57 class G { int a, b; };
58 struct H { private: int a, b; };
59 struct I { protected: int a, b; };
60 struct J { int a, b; void foo (); };
61 struct K { int a, b; virtual void foo (); };
62 struct L : virtual public A { int d, e; };
63 struct M : protected A { int d, e; };
64 struct N : private A { int d, e; };
65 struct O { O () = delete; int a, b, c; };
66 struct P { P () = default; int a, b, c; };
67 typedef int T;
68 typedef float U;
69 typedef int V __attribute__((vector_size (4 * sizeof (int))));
70 typedef double W __attribute__((vector_size (8 * sizeof (double))));
71
72 int
73 main ()
74 {
75 assert (NTEST (void));
76 assert (NTEST (int));
77 assert (NTEST (double));
78 assert (NTEST (T));
79 assert (NTEST (U));
80 assert (PTEST (V));
81 assert (PTEST (W));
82 assert (PTEST (A));
83 assert (PTEST (B));
84 assert (NTEST (C));
85 assert (NTEST (D));
86 #if __cplusplus >= 201703L
87 assert (PTEST (E));
88 #else
89 assert (NTEST (E));
90 #endif
91 assert (NTEST (F));
92 assert (NTEST (G));
93 assert (NTEST (H));
94 assert (NTEST (I));
95 assert (PTEST (J));
96 assert (NTEST (K));
97 assert (NTEST (L));
98 assert (NTEST (M));
99 assert (NTEST (N));
100 #if __cplusplus > 201703L
101 assert (NTEST (O));
102 assert (NTEST (P));
103 #else
104 assert (PTEST (O));
105 assert (PTEST (P));
106 #endif
107 assert (PTEST (int[]));
108 assert (PTEST (double[]));
109 assert (PTEST (T[2]));
110 assert (PTEST (U[]));
111 assert (PTEST (V[]));
112 assert (PTEST (W[]));
113 assert (PTEST (A[19]));
114 assert (PTEST (B[]));
115 assert (PTEST (C[]));
116 assert (PTEST (D[]));
117 assert (PTEST (E[]));
118 assert (PTEST (F[]));
119 assert (PTEST (G[]));
120 assert (PTEST (H[]));
121 assert (PTEST (I[]));
122 assert (PTEST (J[24]));
123 assert (PTEST (K[]));
124 assert (PTEST (L[]));
125 assert (PTEST (M[6]));
126 assert (PTEST (N[]));
127 assert (PTEST (O[]));
128 assert (PTEST (P[]));
129 }