aboutsummaryrefslogtreecommitdiff
path: root/test/SemaTemplate/instantiate-anonymous-union.cpp
blob: 68b233a7fda7d47d04313a27a2ab8543b84d635b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// RUN: %clang_cc1 -fsyntax-only %s -Wall

template <typename T> class A { struct { }; };

A<int> a0;

template <typename T> struct B {
  union {
    int a;
    void* b;
  };
    
  void f() {
    a = 10;
    b = 0;
  }
};

B<int> b0;

template <typename T> struct C {
  union {
    int a;
    void* b;
  };

  C(int a) : a(a) { }
  C(void* b) : b(b) { }
};

C<int> c0(0);

namespace PR7088 {
  template<typename T>
  void f() { 
    union { 
      int a; 
      union {
        float real;
        T d;
      };
    }; 

    a = 17;
    d = 3.14;
  }

  template void f<double>();
}

// Check for problems related to PR7402 that occur when template instantiation
// instantiates implicit initializers.
namespace PR7402 {
  struct X {
    union {
      struct {
        int x;
        int y;
      };
      int v[2];
    };

    // Check that this requirement survives instantiation.
    template <typename T> X(const T& t) : x(t), y(t) {}
  };

  X x(42.0);
}

namespace PR9188 {
  struct X0 {
    union {
      int member;
    };
  };

  static union {
    int global;
  };

  struct X1 : X0 {
    template<typename T>
    int f() {
      return this->X0::member + PR9188::global;
    }
  };

  template int X1::f<int>();
}