Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only %s -Wall |
Douglas Gregor | a5bf7f1 | 2009-08-28 22:03:51 +0000 | [diff] [blame] | 2 | |
| 3 | template <typename T> class A { struct { }; }; |
| 4 | |
| 5 | A<int> a0; |
| 6 | |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 7 | template <typename T> struct B { |
| 8 | union { |
| 9 | int a; |
| 10 | void* b; |
| 11 | }; |
| 12 | |
| 13 | void f() { |
| 14 | a = 10; |
| 15 | b = 0; |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | B<int> b0; |
Anders Carlsson | 9988d5d | 2009-09-01 04:31:02 +0000 | [diff] [blame] | 20 | |
| 21 | template <typename T> struct C { |
| 22 | union { |
| 23 | int a; |
| 24 | void* b; |
| 25 | }; |
| 26 | |
| 27 | C(int a) : a(a) { } |
| 28 | C(void* b) : b(b) { } |
| 29 | }; |
| 30 | |
Anders Carlsson | cdc83c7 | 2009-09-01 06:22:14 +0000 | [diff] [blame] | 31 | C<int> c0(0); |
Douglas Gregor | 9901c57 | 2010-05-21 00:31:19 +0000 | [diff] [blame] | 32 | |
| 33 | namespace PR7088 { |
| 34 | template<typename T> |
| 35 | void f() { |
| 36 | union { |
| 37 | int a; |
| 38 | union { |
| 39 | float real; |
| 40 | T d; |
| 41 | }; |
| 42 | }; |
| 43 | |
| 44 | a = 17; |
| 45 | d = 3.14; |
| 46 | } |
| 47 | |
| 48 | template void f<double>(); |
| 49 | } |
Chandler Carruth | 030ef47 | 2010-09-03 21:54:20 +0000 | [diff] [blame] | 50 | |
| 51 | // Check for problems related to PR7402 that occur when template instantiation |
| 52 | // instantiates implicit initializers. |
| 53 | namespace PR7402 { |
| 54 | struct X { |
| 55 | union { |
| 56 | struct { |
| 57 | int x; |
| 58 | int y; |
| 59 | }; |
| 60 | int v[2]; |
| 61 | }; |
| 62 | |
| 63 | // Check that this requirement survives instantiation. |
| 64 | template <typename T> X(const T& t) : x(t), y(t) {} |
| 65 | }; |
| 66 | |
| 67 | X x(42.0); |
| 68 | } |
Douglas Gregor | f584832 | 2011-02-18 02:44:58 +0000 | [diff] [blame] | 69 | |
| 70 | namespace PR9188 { |
| 71 | struct X0 { |
| 72 | union { |
| 73 | int member; |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | static union { |
| 78 | int global; |
| 79 | }; |
| 80 | |
| 81 | struct X1 : X0 { |
| 82 | template<typename T> |
| 83 | int f() { |
| 84 | return this->X0::member + PR9188::global; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | template int X1::f<int>(); |
| 89 | } |