Debian Codegraph @

gcc/testsuite/g++.dg/ext/is_union.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 class B
12 {
13 B() { }
14 };
15
16 union U
17 {
18 double a;
19 double b;
20 };
21
22 template<typename T>
23 bool
24 f()
25 { return __is_union(T); }
26
27 template<typename T>
28 class My
29 {
30 public:
31 bool
32 f()
33 { return !!__is_union(T); }
34 };
35
36 template<typename T>
37 class My2
38 {
39 public:
40 static const bool trait = __is_union(T);
41 };
42
43 template<typename T>
44 const bool My2<T>::trait;
45
46 template<typename T, bool b = __is_union(T)>
47 struct My3_help
48 { static const bool trait = b; };
49
50 template<typename T, bool b>
51 const bool My3_help<T, b>::trait;
52
53 template<typename T>
54 class My3
55 {
56 public:
57 bool
58 f()
59 { return My3_help<T>::trait; }
60 };
61
62 #define PTEST(T) (__is_union(T) && f<T>() \
63 && My<T>().f() && My2<T>::trait && My3<T>().f())
64
65 #define NTEST(T) (!__is_union(T) && !f<T>() \
66 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
67
68 int main()
69 {
70 assert (NTEST (int));
71 assert (NTEST (void));
72 assert (NTEST (A));
73 assert (NTEST (B));
74 assert (PTEST (U));
75
76 return 0;
77 }