xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/instantiate-anonymous-union.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only %s -Wall
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc template <typename T> class A { struct { }; };
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc A<int> a0;
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc template <typename T> struct B {
8*f4a2713aSLionel Sambuc   union {
9*f4a2713aSLionel Sambuc     int a;
10*f4a2713aSLionel Sambuc     void* b;
11*f4a2713aSLionel Sambuc   };
12*f4a2713aSLionel Sambuc 
fB13*f4a2713aSLionel Sambuc   void f() {
14*f4a2713aSLionel Sambuc     a = 10;
15*f4a2713aSLionel Sambuc     b = 0;
16*f4a2713aSLionel Sambuc   }
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc B<int> b0;
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc template <typename T> struct C {
22*f4a2713aSLionel Sambuc   union {
23*f4a2713aSLionel Sambuc     int a;
24*f4a2713aSLionel Sambuc     void* b;
25*f4a2713aSLionel Sambuc   };
26*f4a2713aSLionel Sambuc 
CC27*f4a2713aSLionel Sambuc   C(int a) : a(a) { }
CC28*f4a2713aSLionel Sambuc   C(void* b) : b(b) { }
29*f4a2713aSLionel Sambuc };
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc C<int> c0(0);
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc namespace PR7088 {
34*f4a2713aSLionel Sambuc   template<typename T>
f()35*f4a2713aSLionel Sambuc   void f() {
36*f4a2713aSLionel Sambuc     union {
37*f4a2713aSLionel Sambuc       int a;
38*f4a2713aSLionel Sambuc       union {
39*f4a2713aSLionel Sambuc         float real;
40*f4a2713aSLionel Sambuc         T d;
41*f4a2713aSLionel Sambuc       };
42*f4a2713aSLionel Sambuc     };
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc     a = 17;
45*f4a2713aSLionel Sambuc     d = 3.14;
46*f4a2713aSLionel Sambuc   }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc   template void f<double>();
49*f4a2713aSLionel Sambuc }
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc // Check for problems related to PR7402 that occur when template instantiation
52*f4a2713aSLionel Sambuc // instantiates implicit initializers.
53*f4a2713aSLionel Sambuc namespace PR7402 {
54*f4a2713aSLionel Sambuc   struct X {
55*f4a2713aSLionel Sambuc     union {
56*f4a2713aSLionel Sambuc       struct {
57*f4a2713aSLionel Sambuc         int x;
58*f4a2713aSLionel Sambuc         int y;
59*f4a2713aSLionel Sambuc       };
60*f4a2713aSLionel Sambuc       int v[2];
61*f4a2713aSLionel Sambuc     };
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc     // Check that this requirement survives instantiation.
XPR7402::X64*f4a2713aSLionel Sambuc     template <typename T> X(const T& t) : x(t), y(t) {}
65*f4a2713aSLionel Sambuc   };
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc   X x(42.0);
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc namespace PR9188 {
71*f4a2713aSLionel Sambuc   struct X0 {
72*f4a2713aSLionel Sambuc     union {
73*f4a2713aSLionel Sambuc       int member;
74*f4a2713aSLionel Sambuc     };
75*f4a2713aSLionel Sambuc   };
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc   static union {
78*f4a2713aSLionel Sambuc     int global;
79*f4a2713aSLionel Sambuc   };
80*f4a2713aSLionel Sambuc 
81*f4a2713aSLionel Sambuc   struct X1 : X0 {
82*f4a2713aSLionel Sambuc     template<typename T>
fPR9188::X183*f4a2713aSLionel Sambuc     int f() {
84*f4a2713aSLionel Sambuc       return this->X0::member + PR9188::global;
85*f4a2713aSLionel Sambuc     }
86*f4a2713aSLionel Sambuc   };
87*f4a2713aSLionel Sambuc 
88*f4a2713aSLionel Sambuc   template int X1::f<int>();
89*f4a2713aSLionel Sambuc }
90