// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z // Template argument deduction with template template parameters. template class A> struct X0 { static const unsigned value = 0; }; template class A> struct X0 { static const unsigned value = 1; }; template struct X0i; template struct X0l; int array_x0a[X0::value == 0? 1 : -1]; int array_x0b[X0::value == 1? 1 : -1]; template struct is_same { static const bool value = false; }; template struct is_same { static const bool value = true; }; template struct allocator { }; template > struct vector {}; // Fun with meta-lambdas! struct _1 {}; struct _2 {}; // Replaces all occurrences of _1 with Arg1 and _2 with Arg2 in T. template struct Replace { typedef T type; }; // Replacement of the whole type. template struct Replace<_1, Arg1, Arg2> { typedef Arg1 type; }; template struct Replace<_2, Arg1, Arg2> { typedef Arg2 type; }; // Replacement through cv-qualifiers template struct Replace { typedef typename Replace::type const type; }; // Replacement of templates template class TT, typename T1, typename Arg1, typename Arg2> struct Replace, Arg1, Arg2> { typedef TT::type> type; }; template class TT, typename T1, typename T2, typename Arg1, typename Arg2> struct Replace, Arg1, Arg2> { typedef TT::type, typename Replace::type> type; }; // Just for kicks... template class TT, typename T1, typename Arg1, typename Arg2> struct Replace, Arg1, Arg2> { typedef TT::type, Arg2> type; }; int array0[is_same::type, int>::value? 1 : -1]; int array1[is_same::type, const int>::value? 1 : -1]; int array2[is_same, int, float>::type, vector >::value? 1 : -1]; int array3[is_same, int, float>::type, vector >::value? 1 : -1]; int array4[is_same, double, float>::type, vector >::value? 1 : -1]; // PR5911 template void f(const T (&a)[N]); int iarr[] = { 1 }; void test_PR5911() { f(iarr); } // Must not examine base classes of incomplete type during template argument // deduction. namespace PR6257 { template struct X { template X(const X& u); }; struct A; void f(A& a); void f(const X& a); void test(A& a) { (void)f(a); } } // PR7463 namespace PR7463 { const int f (); template void g (T_&); // expected-note{{T_ = int}} void h (void) { g(f()); } // expected-error{{no matching function for call}} } namespace test0 { template void make(const T *(*fn)()); // expected-note {{candidate template ignored: cannot deduce a type for 'T' that would make 'const T' equal 'char'}} char *char_maker(); void test() { make(char_maker); // expected-error {{no matching function for call to 'make'}} } } namespace test1 { template void foo(const T a[3][3]); void test() { int a[3][3]; foo(a); } } // PR7708 namespace test2 { template struct Const { typedef void const type; }; template void f(T, typename Const::type*); template void f(T, void const *); void test() { void *p = 0; f(0, p); } } // rdar://problem/8537391 namespace test3 { struct Foo { template static inline void foo(); }; class Bar { template static inline void wobble(T ch); public: static void madness() { Foo::foo >(); } }; } // Verify that we can deduce enum-typed arguments correctly. namespace test14 { enum E { E0, E1 }; template struct A {}; template void foo(const A &a) {} void test() { A a; foo(a); } } namespace PR21536 { template struct X; template struct S { static_assert(sizeof...(B) == 1, ""); void f() { using T = A; using T = int; using U = X; using U = X; } }; template void f(S); void g() { f(S()); } } namespace PR19372 { template class C, typename ...Us> struct BindBack { template using apply = C; }; template struct Y; template using Z = Y; using T = BindBack::apply<>; using T = Z; using U = BindBack::apply; using U = Z; namespace BetterReduction { template struct S; template using X = S; // expected-note {{parameter}} template using Y = X; template using Z = X; // expected-error {{must be a type}} using T = Y; using T = S; } } namespace PR18645 { template F Quux(F &&f); auto Baz = Quux(Quux); } namespace NonDeducedNestedNameSpecifier { template struct A { template struct B { B(int) {} }; }; template int f(A, typename A::template B); int k = f(A(), 0); } namespace PR27601_RecursivelyInheritedBaseSpecializationsDeductionAmbiguity { namespace ns1 { template struct B { }; template struct B : B<> { }; template struct D : B { }; template void f(B &) { } int main() { D d; f(d); } } //end ns1 namespace ns2 { template struct tup_impl; template struct tup_impl {}; // empty tail template struct tup_impl : tup_impl { using value_type = Head; Head head; }; template struct tup : tup_impl<0, Es...> {}; template Head &get_helper(tup_impl &t) { return t.head; } template Head const &get_helper(tup_impl const &t) { return t.head; } int main() { tup t; get_helper(t); return 0; } } // end ns2 } namespace multiple_deduction_different_type { template struct X {}; template class X, typename T, typename U, int N> void f(X, X) {} // expected-note 2{{values of conflicting types}} template class X, typename T, typename U, const int *N> void g(X, X) {} // expected-note 0-2{{values of conflicting types}} int n; void h() { f(X(), X()); // expected-error {{no matching function}} f(X(), X()); // expected-error {{no matching function}} #if __cplusplus > 201402L g(X(), X()); // expected-error {{no matching function}} g(X(), X()); // expected-error {{no matching function}} #endif } template class X, typename T, typename U, T N> void x(X, int(*)[N], X) {} // expected-note 1+{{candidate}} template class X, typename T, typename U, T N> void x(int(*)[N], X, X) {} // expected-note 1+{{candidate}} int arr[3]; void y() { x(X(), &arr, X()); x(&arr, X(), X()); x(X(), &arr, X()); // expected-error {{no matching function}} x(&arr, X(), X()); // expected-error {{no matching function}} x(X(), &arr, X()); x(&arr, X(), X()); } } namespace nullptr_deduction { using nullptr_t = decltype(nullptr); template struct X {}; template void f(X) { static_assert(!v, ""); } void g() { f(X()); f(X()); } template class X, typename T, typename U, int *P> void f1(X, X) {} // expected-note 2{{values of conflicting types}} void h() { f1(X(), X()); // expected-error {{no matching function}} f1(X(), X()); // expected-error {{no matching function}} } template class X, typename T, typename U, nullptr_t P> void f2(X, X) {} // expected-note 2{{values of conflicting types}} void i() { f2(X(), X()); // expected-error {{no matching function}} f2(X(), X()); // expected-error {{no matching function}} } } namespace member_pointer { struct A { void f(int); }; template struct B; template struct C; template struct C> { C() { A a; T t; (a.*F)(t); } }; C> c; } namespace deduction_substitution_failure { template struct Fail { typedef typename T::error error; }; // expected-error 2{{prior to '::'}} template struct A {}; template struct A::error> {}; // expected-note {{instantiation of}} A ai; // expected-note {{during template argument deduction for class template partial specialization 'A::error>' [with T = int]}} template int B; // expected-warning 0-1 {{extension}} template int B::error> {}; // expected-note {{instantiation of}} int bi = B; // expected-note {{during template argument deduction for variable template partial specialization 'B::error>' [with T = char]}} } namespace deduction_after_explicit_pack { template int *f(T ...t, int &r, U *u) { // expected-note {{couldn't infer template argument 'U'}} return u; } template int *g(T ...t, int &r, U *u) { return u; } void h(float a, double b, int c) { // FIXME: Under DR1388, this appears to be valid. f(a, b, c, &c); // expected-error {{no matching}} g(a, b, c, &c); // ok } } namespace overload_vs_pack { void f(int); void f(float); void g(double); template struct X {}; template void x(T...); template struct Y { typedef int type(typename T::error...); }; template<> struct Y { typedef int type; }; template typename Y::type g1(X, void (*...fns)(T)); // expected-note {{deduced conflicting types for parameter 'T' ( vs. <(no value), double>)}} template typename Y::type g2(void(*)(T...), void (*...fns)(T)); // expected-note {{deduced conflicting types for parameter 'T' ( vs. <(no value), double>)}} template int &h1(decltype(g1(X(), f, f, g)) *p); template float &h1(...); template int &h2(decltype(g2(x, f, f, g)) *p); template float &h2(...); int n1 = g1(X(), f, g); // expected-error {{no matching function}} int n2 = g2(x, f, g); // expected-error {{no matching function}} int &a1 = h1(0); // ok, skip deduction for 'f's, deduce matching value from 'g' int &a2 = h2(0); float &b1 = h1(0); // deduce mismatching value from 'g', so we do not trigger instantiation of Y float &b2 = h2(0); template int partial_deduction(void (*...f)(T)); // expected-note {{deduced incomplete pack <(no value), double> for template parameter 'T'}} int pd1 = partial_deduction(f, g); // expected-error {{no matching function}} template int partial_deduction_2(void (*...f)(T), ...); // expected-note {{deduced incomplete pack <(no value), double> for template parameter 'T'}} int pd2 = partial_deduction_2(f, g); // expected-error {{no matching function}} namespace cwg_example { void f(char, char); void f(int, int); void x(int, char); template void j(void(*)(U...), void (*...fns)(T, U)); void test() { j(x, f, x); } } } namespace b29946541 { template class A {}; template class C> void f(C); // expected-note {{failed template argument deduction}} void g(A a) { f(a); } // expected-error {{no match}} } namespace deduction_from_empty_list { template void f(int (&&)[N], int (&&)[N]) { // expected-note {{1 vs. 2}} static_assert(M == N, ""); } void test() { f<5>({}, {}); f<1>({}, {0}); f<1>({0}, {}); f<1>({0}, {0}); f<1>({0}, {0, 1}); // expected-error {{no matching}} } } namespace check_extended_pack { template struct X { typedef int type; }; template void f(typename X::type...); template void f(T, int, int); void g() { f(0, 0, 0); } template struct Y {}; template void g(Y); // expected-note {{deduced non-type template argument does not have the same type as the corresponding template parameter ('int *' vs 'int')}} int n; void h() { g<0>(Y<0, &n>()); } // expected-error {{no matching function}} }