323 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s2 3template<typename S>4struct 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 19A<int> a;20A<char>::D<double> b;21 22template<typename T> T make();23 24namespace 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 48 thing(traits_type &traits) : traits(traits), val(traits.alloc()) {}49 ~thing() { traits.free(static_cast<inner_ptr&&>(val)); }50 51 traits_type &traits;52 inner_ptr val;53 54 friend inner_ptr val(const thing &t) { return t.val; }55 };56 57 template<> struct ptr_traits<bool> {58 typedef bool &type;59 };60 template<> bool &traits<thing<bool>>::alloc() { static bool b; return b; }61 template<> void traits<thing<bool>>::free(bool&) {}62}63 64typedef X::traits<X::thing<int>> itt;65 66itt::thing::traits_type itr;67itt::thing ith(itr);68 69itt::rebind<bool> btr;70itt::rebind_thing<bool> btt(btr);71 72namespace PR11848 {73 template<typename T> using U = int;74 75 template<typename T, typename ...Ts>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>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>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 87 void g() {88 f1(U<void>()); // expected-error {{no match}}89 f1(1, 2, 3, 4, 5); // expected-error {{no match}}90 f2(); // ok91 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 121namespace 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 or127 // value dependent. This is true even if the expression's type is a pack128 // expansion type.129 void f1(Y<T> a) { h(g(a)); } // expected-error {{undeclared identifier 'g'}}130 void f2(Y<Ts>...as) { h(g(as)...); } // expected-error {{undeclared identifier 'g'}}131 void f3(Y<Ts>...as) { g(as...); } // ok132 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 because134 // 'g' never has any associated namespaces.135 void f5(Ts ...ts) { g(sizeof(ts)...); } // ok136 };137}138 139namespace PR13243 {140 template<typename A> struct X {};141 template<int I> struct C {};142 template<int I> using Ci = C<I>;143 144 template<typename A, int I> void f(X<A>, Ci<I>) {}145 template void f(X<int>, C<0>);146}147 148namespace 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 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 168namespace 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);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);185 void f() {186 f(Zero<X,X,X>());187 }188 }189}190 191namespace PR16904 {192 template <typename,typename>193 struct base {194 template <typename> struct derived;195 };196 template <typename T, typename U, typename V>197 using derived = base<T, U>::template derived<V>; // expected-warning {{missing 'typename'}}198 template <typename T, typename U, typename V>199 using derived2 = ::PR16904::base<T, U>::template derived<V>; // expected-warning {{missing 'typename'}}200}201 202namespace PR14858 {203 template<typename ...T> using X = int[sizeof...(T)];204 205 template<typename ...U> struct Y {206 using Z = X<U...>;207 };208 using A = Y<int, int, int, int>::Z;209 using A = int[4];210 211 // FIXME: These should be treated as being redeclarations.212 template<typename ...T> void f(X<T...> &) {}213 template<typename ...T> void f(int(&)[sizeof...(T)]) {}214 215 template<typename ...T> void g(X<typename T::type...> &) {}216 template<typename ...T> void g(int(&)[sizeof...(T)]) {} // ok, different217 218 template<typename ...T, typename ...U> void h(X<T...> &) {}219 template<typename ...T, typename ...U> void h(X<U...> &) {} // ok, different220 221 template<typename ...T> void i(auto (T ...t) -> int(&)[sizeof...(t)]);222 auto mk_arr(int, int) -> int(&)[2];223 void test_i() { i<int, int>(mk_arr); }224 225#if 0 // FIXME: This causes clang to assert.226 template<typename ...T> using Z = auto (T ...p) -> int (&)[sizeof...(p)];227 template<typename ...T, typename ...U> void j(Z<T..., U...> &) {}228 void test_j() { j<int, int>(mk_arr); }229#endif230 231 template<typename ...T> struct Q {232 template<typename ...U> using V = int[sizeof...(U)];233 template<typename ...U> void f(V<typename U::type..., typename T::type...> *);234 };235 struct B { typedef int type; };236 void test_q(int (&a)[5]) { Q<B, B, B>().f<B, B>(&a); }237}238 239namespace PR84220 {240 241template <class...> class list {};242 243template <int> struct foo_impl {244 template <class> using f = int;245};246 247template <class... xs>248using foo = typename foo_impl<sizeof...(xs)>::template f<xs...>;249 250// We call getFullyPackExpandedSize at the annotation stage251// before parsing the ellipsis next to the foo<xs>. This happens before252// a PackExpansionType is formed for foo<xs>.253// getFullyPackExpandedSize shouldn't determine the value here. Otherwise,254// foo_impl<sizeof...(xs)> would lose its dependency despite the template255// arguments being unsubstituted.256template <class... xs> using test = list<foo<xs>...>;257 258test<int> a;259 260}261 262namespace redecl {263 template<typename> using A = int;264 template<typename = void> using A = int;265 A<> a; // ok266}267 268namespace PR31514 {269 template<typename T, typename> using EnableTupleSize = T;270 271 template<typename T> struct tuple_size { static const int value = 0; };272 template<typename T> struct tuple_size<EnableTupleSize<const T, decltype(tuple_size<T>::value)>> {};273 template<typename T> struct tuple_size<EnableTupleSize<volatile T, decltype(tuple_size<T>::value)>> {};274 275 tuple_size<const int> t;276}277 278namespace an_alias_template_is_not_a_class_template {279 template<typename T> using Foo = int; // expected-note 3{{here}}280 Foo x; // expected-error {{use of alias template 'Foo' requires template arguments}}281 Foo<> y; // expected-error {{too few template arguments for alias template 'Foo'}}282 int z = Foo(); // expected-error {{use of alias template 'Foo' requires template arguments}}283 284 template<template<typename> class Bar> void f() { // expected-note 3{{here}}285 Bar x; // expected-error {{use of template template parameter 'Bar' requires template arguments}}286 Bar<> y; // expected-error {{too few template arguments for template template parameter 'Bar'}}287 int z = Bar(); // expected-error {{use of template template parameter 'Bar' requires template arguments}}288 }289}290 291namespace resolved_nttp {292 template <typename T> struct A {293 template <int N> using Arr = T[N];294 Arr<3> a;295 };296 using TA = decltype(A<int>::a);297 using TA = int[3];298 299 template <typename T> struct B {300 template <int... N> using Fn = T(int(*...A)[N]);301 Fn<1, 2, 3> *p;302 };303 using TB = decltype(B<int>::p);304 using TB = int (*)(int (*)[1], int (*)[2], int (*)[3]);305 306 template <typename T, int ...M> struct C {307 template <T... N> using Fn = T(int(*...A)[N]);308 Fn<1, M..., 4> *p; // expected-error-re 3{{evaluates to {{[234]}}, which cannot be narrowed to type 'bool'}}309 };310 using TC = decltype(C<int, 2, 3>::p);311 using TC = int (*)(int (*)[1], int (*)[2], int (*)[3], int (*)[4]);312 313 using TC2 = decltype(C<bool, 2, 3>::p); // expected-note {{instantiation of}}314}315 316namespace OuterSubstFailure {317 template <class T> struct A {318 template <class> using B = T&;319 // expected-error@-1 {{cannot form a reference to 'void'}}320 };321 template struct A<void>; // expected-note {{requested here}}322} // namespace OuterSubstFailure323