1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 3 template<typename S> 4 struct A { 5 typedef S B; 6 template<typename T> using C = typename T::B; 7 template<typename T> struct D { 8 template<typename U> using E = typename A<U>::template C<A<T>>; 9 template<typename U> using F = A<E<U>>; 10 template<typename U> using G = C<F<U>>; 11 G<T> g; 12 }; 13 typedef decltype(D<B>().g) H; 14 D<H> h; 15 template<typename T> using I = A<decltype(h.g)>; 16 template<typename T> using J = typename A<decltype(h.g)>::template C<I<T>>; 17 }; 18 19 A<int> a; 20 A<char>::D<double> b; 21 22 template<typename T> T make(); 23 24 namespace X { 25 template<typename T> struct traits { 26 typedef T thing; 27 typedef decltype(val(make<thing>())) inner_ptr; 28 29 template<typename U> using rebind_thing = typename thing::template rebind<U>; 30 template<typename U> using rebind = traits<rebind_thing<U>>; 31 32 inner_ptr &&alloc(); 33 void free(inner_ptr&&); 34 }; 35 36 template<typename T> struct ptr_traits { 37 typedef T *type; 38 }; 39 template<typename T> using ptr = typename ptr_traits<T>::type; 40 41 template<typename T> struct thing { 42 typedef T inner; 43 typedef ptr<inner> inner_ptr; 44 typedef traits<thing<inner>> traits_type; 45 46 template<typename U> using rebind = thing<U>; 47 thingX::thing48 thing(traits_type &traits) : traits(traits), val(traits.alloc()) {} ~thingX::thing49 ~thing() { traits.free(static_cast<inner_ptr&&>(val)); } 50 51 traits_type &traits; 52 inner_ptr val; 53 val(const thing & t)54 friend inner_ptr val(const thing &t) { return t.val; } 55 }; 56 57 template<> struct ptr_traits<bool> { 58 typedef bool &type; 59 }; alloc()60 template<> bool &traits<thing<bool>>::alloc() { static bool b; return b; } free(bool &)61 template<> void traits<thing<bool>>::free(bool&) {} 62 } 63 64 typedef X::traits<X::thing<int>> itt; 65 66 itt::thing::traits_type itr; 67 itt::thing ith(itr); 68 69 itt::rebind<bool> btr; 70 itt::rebind_thing<bool> btt(btr); 71 72 namespace PR11848 { 73 template<typename T> using U = int; 74 75 template<typename T, typename ...Ts> f1(U<T> i,U<Ts>...is)76 void f1(U<T> i, U<Ts> ...is) { // expected-note 2{{couldn't infer template argument 'T'}} 77 return i + f1<Ts...>(is...); 78 } 79 80 template<typename ...Ts> f2(U<Ts>...is)81 void f2(U<Ts> ...is) { } // expected-note {{deduced incomplete pack <(no value)> for template parameter 'Ts'}} 82 83 template<typename...> struct type_tuple {}; 84 template<typename ...Ts> f3(type_tuple<Ts...>,U<Ts>...is)85 void f3(type_tuple<Ts...>, U<Ts> ...is) {} // expected-note {{deduced packs of different lengths for parameter 'Ts' (<void, void, void> vs. <(no value), (no value)>)}} 86 g()87 void g() { 88 f1(U<void>()); // expected-error {{no match}} 89 f1(1, 2, 3, 4, 5); // expected-error {{no match}} 90 f2(); // ok 91 f2(1); // expected-error {{no match}} 92 f3(type_tuple<>()); 93 f3(type_tuple<void, void, void>(), 1, 2); // expected-error {{no match}} 94 f3(type_tuple<void, void, void>(), 1, 2, 3); 95 } 96 97 template<typename ...Ts> 98 struct S { 99 S(U<Ts>...ts); 100 }; 101 102 template<typename T> 103 struct Hidden1 { 104 template<typename ...Ts> 105 Hidden1(typename T::template U<Ts> ...ts); 106 }; 107 108 template<typename T, typename ...Ts> 109 struct Hidden2 { 110 Hidden2(typename T::template U<Ts> ...ts); 111 }; 112 113 struct Hide { 114 template<typename T> using U = int; 115 }; 116 117 Hidden1<Hide> h1; 118 Hidden2<Hide, double, char> h2(1, 2); 119 } 120 121 namespace Core22036 { 122 struct X {}; 123 void h(...); 124 template<typename T> using Y = X; 125 template<typename T, typename ...Ts> struct S { 126 // An expression can contain an unexpanded pack without being type or 127 // value dependent. This is true even if the expression's type is a pack 128 // expansion type. f1Core22036::S129 void f1(Y<T> a) { h(g(a)); } // expected-error {{undeclared identifier 'g'}} f2Core22036::S130 void f2(Y<Ts>...as) { h(g(as)...); } // expected-error {{undeclared identifier 'g'}} f3Core22036::S131 void f3(Y<Ts>...as) { g(as...); } // ok f4Core22036::S132 void f4(Ts ...ts) { h(g(sizeof(ts))...); } // expected-error {{undeclared identifier 'g'}} 133 // FIXME: We can reject this, since it has no valid instantiations because 134 // 'g' never has any associated namespaces. f5Core22036::S135 void f5(Ts ...ts) { g(sizeof(ts)...); } // ok 136 }; 137 } 138 139 namespace PR13243 { 140 template<typename A> struct X {}; 141 template<int I> struct C {}; 142 template<int I> using Ci = C<I>; 143 f(X<A>,Ci<I>)144 template<typename A, int I> void f(X<A>, Ci<I>) {} 145 template void f(X<int>, C<0>); 146 } 147 148 namespace PR13136 { 149 template <typename T, T... Numbers> 150 struct NumberTuple { }; 151 152 template <unsigned int... Numbers> 153 using MyNumberTuple = NumberTuple<unsigned int, Numbers...>; 154 155 template <typename U, unsigned int... Numbers> 156 void foo(U&&, MyNumberTuple<Numbers...>); 157 158 template <typename U, unsigned int... Numbers> 159 void bar(U&&, NumberTuple<unsigned int, Numbers...>); 160 main()161 int main() { 162 foo(1, NumberTuple<unsigned int, 0, 1>()); 163 bar(1, NumberTuple<unsigned int, 0, 1>()); 164 return 0; 165 } 166 } 167 168 namespace PR16646 { 169 namespace test1 { 170 template <typename T> struct DefaultValue { const T value=0;}; 171 template <typename ... Args> struct tuple {}; 172 template <typename ... Args> using Zero = tuple<DefaultValue<Args> ...>; 173 template <typename ... Args> void f(const Zero<Args ...> &t); f()174 void f() { 175 f(Zero<int,double,double>()); 176 } 177 } 178 179 namespace test2 { 180 template<int x> struct X {}; 181 template <template<int x> class temp> struct DefaultValue { const temp<0> value; }; 182 template <typename ... Args> struct tuple {}; 183 template <template<int x> class... Args> using Zero = tuple<DefaultValue<Args> ...>; 184 template <template<int x> class... Args> void f(const Zero<Args ...> &t); f()185 void f() { 186 f(Zero<X,X,X>()); 187 } 188 } 189 } 190 191 namespace PR16904 { 192 template <typename,typename> 193 struct base { 194 template <typename> struct derived; 195 }; 196 // FIXME: The diagnostics here are terrible. 197 template <typename T, typename U, typename V> 198 using derived = base<T, U>::template derived<V>; // expected-error {{expected a type}} expected-error {{expected ';'}} 199 template <typename T, typename U, typename V> 200 using derived2 = ::PR16904::base<T, U>::template derived<V>; // expected-error {{expected a type}} expected-error {{expected ';'}} 201 } 202 203 namespace PR14858 { 204 template<typename ...T> using X = int[sizeof...(T)]; 205 206 template<typename ...U> struct Y { 207 using Z = X<U...>; 208 }; 209 using A = Y<int, int, int, int>::Z; 210 using A = int[4]; 211 212 // FIXME: These should be treated as being redeclarations. f(X<T...> &)213 template<typename ...T> void f(X<T...> &) {} f(int (&)[sizeof...(T)])214 template<typename ...T> void f(int(&)[sizeof...(T)]) {} 215 g(X<typename T::type...> &)216 template<typename ...T> void g(X<typename T::type...> &) {} g(int (&)[sizeof...(T)])217 template<typename ...T> void g(int(&)[sizeof...(T)]) {} // ok, different 218 h(X<T...> &)219 template<typename ...T, typename ...U> void h(X<T...> &) {} h(X<U...> &)220 template<typename ...T, typename ...U> void h(X<U...> &) {} // ok, different 221 222 template<typename ...T> void i(auto (T ...t) -> int(&)[sizeof...(t)]); 223 auto mk_arr(int, int) -> int(&)[2]; test_i()224 void test_i() { i<int, int>(mk_arr); } 225 226 #if 0 // FIXME: This causes clang to assert. 227 template<typename ...T> using Z = auto (T ...p) -> int (&)[sizeof...(p)]; 228 template<typename ...T, typename ...U> void j(Z<T..., U...> &) {} 229 void test_j() { j<int, int>(mk_arr); } 230 #endif 231 232 template<typename ...T> struct Q { 233 template<typename ...U> using V = int[sizeof...(U)]; 234 template<typename ...U> void f(V<typename U::type..., typename T::type...> *); 235 }; 236 struct B { typedef int type; }; test_q(int (& a)[5])237 void test_q(int (&a)[5]) { Q<B, B, B>().f<B, B>(&a); } 238 } 239 240 namespace redecl { 241 template<typename> using A = int; 242 template<typename = void> using A = int; 243 A<> a; // ok 244 } 245 246 namespace PR31514 { 247 template<typename T, typename> using EnableTupleSize = T; 248 249 template<typename T> struct tuple_size { static const int value = 0; }; 250 template<typename T> struct tuple_size<EnableTupleSize<const T, decltype(tuple_size<T>::value)>> {}; 251 template<typename T> struct tuple_size<EnableTupleSize<volatile T, decltype(tuple_size<T>::value)>> {}; 252 253 tuple_size<const int> t; 254 } 255 256 namespace an_alias_template_is_not_a_class_template { 257 template<typename T> using Foo = int; // expected-note 3{{here}} 258 Foo x; // expected-error {{use of alias template 'Foo' requires template arguments}} 259 Foo<> y; // expected-error {{too few template arguments for alias template 'Foo'}} 260 int z = Foo(); // expected-error {{use of alias template 'Foo' requires template arguments}} 261 f()262 template<template<typename> class Bar> void f() { // expected-note 3{{here}} 263 Bar x; // expected-error {{use of template template parameter 'Bar' requires template arguments}} 264 Bar<> y; // expected-error {{too few template arguments for template template parameter 'Bar'}} 265 int z = Bar(); // expected-error {{use of template template parameter 'Bar' requires template arguments}} 266 } 267 } 268