summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate/instantiate-expr-2.cpp
blob: b91b398a80e35e06a0d2250de68e981d3c02a907 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// RUN: %clang_cc1 -fsyntax-only %s
typedef char one_byte;
typedef char (&two_bytes)[2];
typedef char (&four_bytes)[4];
typedef char (&eight_bytes)[8];

template<int N> struct A { };

namespace N1 {
  struct X { };
}

namespace N2 {
  struct Y { };

  two_bytes operator+(Y, Y);
}

namespace N3 {
  struct Z { };

  eight_bytes operator+(Z, Z);
}

namespace N4 {
  one_byte operator+(N1::X, N2::Y);

  template<typename T, typename U>
  struct BinOpOverload {
    typedef A<sizeof(T() + U())> type;
  };
}

namespace N1 {
  four_bytes operator+(X, X);
}

namespace N3 {
  eight_bytes operator+(Z, Z); // redeclaration
}

void test_bin_op_overload(A<1> *a1, A<2> *a2, A<4> *a4, A<8> *a8) {
  typedef N4::BinOpOverload<N1::X, N2::Y>::type XY;
  XY *xy = a1;
  typedef N4::BinOpOverload<N1::X, N1::X>::type XX;
  XX *xx = a4;
  typedef N4::BinOpOverload<N2::Y, N2::Y>::type YY;
  YY *yy = a2;
  typedef N4::BinOpOverload<N3::Z, N3::Z>::type ZZ;
  ZZ *zz = a8;
}

namespace N3 {
  eight_bytes operator-(::N3::Z);
}

namespace N4 {
  template<typename T>
  struct UnaryOpOverload {
    typedef A<sizeof(-T())> type;
  };
}

void test_unary_op_overload(A<8> *a8) {
  typedef N4::UnaryOpOverload<N3::Z>::type UZ;
  UZ *uz = a8;
}

/*
namespace N5 {
  template<int I>
  struct Lookup {
    enum { val = I, more = val + 1 };
  };

  template<bool B>
  struct Cond {
    enum Junk { is = B ? Lookup<B>::more : Lookup<Lookup<B+1>::more>::val };
  };

  enum { resultT = Cond<true>::is,
         resultF = Cond<false>::is };
}
*/

namespace N6 {
  // non-typedependent
  template<int I>
  struct Lookup {};

  template<bool B, typename T, typename E>
  struct Cond {
    typedef Lookup<B ? sizeof(T) : sizeof(E)> True;
    typedef Lookup<!B ? sizeof(T) : sizeof(E)> False;
  };

  typedef Cond<true, int, char>::True True;
  typedef Cond<true, int, char>::False False;

  // check that we have the right types
  Lookup<1> const &L1(False());
  Lookup<sizeof(int)> const &L2(True());
}


namespace N7 {
  // type dependent
  template<int I>
  struct Lookup {};

  template<bool B, typename T, typename E>
  struct Cond {
    T foo() { return B ? T() : E(); }
    typedef Lookup<sizeof(B ? T() : E())> Type;
  };

  //Cond<true, int*, double> C; // Errors
  //int V(C.foo()); // Errors
  //typedef Cond<true, int*, double>::Type Type; // Errors
  typedef Cond<true, int, double>::Type Type;
}

template<typename T, unsigned long N> struct IntegralConstant { };

template<typename T>
struct X0 {
  void f(T x, IntegralConstant<T, sizeof(x)>);
};

void test_X0(X0<int> x, IntegralConstant<int, sizeof(int)> ic) {
  x.f(5,ic);
}

namespace N8 {
  struct X {
    X operator+(const X&) const;
  };
  
  template<typename T>
  T test_plus(const T* xp, const T& x, const T& y) {
    x.operator+(y);
    return xp->operator+(y);
  }
  
  void test_test_plus(X x) {
    test_plus(&x, x, x);
  }
}

namespace N9 {
  struct A {
    bool operator==(int value);
  };
  
  template<typename T> struct B {
    bool f(A a) {
      return a == 1;
    }
  };
  
  template struct B<int>;  
}

namespace N10 {
  template <typename T>
  class A {
    struct X { };
    
  public:
    ~A() {
      f(reinterpret_cast<X *>(0), reinterpret_cast<X *>(0));
    }
    
  private:
    void f(X *);
    void f(X *, X *);
  };
  
  template class A<int>;
}

namespace N12 {
  // PR5224
  template<typename T>
  struct A { typedef int t0; };
  
  struct C  {
    C(int);
    
    template<typename T>
    static C *f0(T a0) {return new C((typename A<T>::t0) 1);   }
  };

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

namespace N13 {
  class A{
    A(const A&);

  public:
    ~A();
    A(int);
    template<typename T> A &operator<<(const T&);
  };

  template<typename T>
  void f(T t) {
    A(17) << t;
  }

  template void f(int);

}
OpenPOWER on IntegriCloud