1eff92135d32039c9874dc356f3e93143af6069c1John McCall// RUN: %clang_cc1 -fsyntax-only -verify %s 2eff92135d32039c9874dc356f3e93143af6069c1John McCall 3eff92135d32039c9874dc356f3e93143af6069c1John McCallnamespace test0 { 4a933319ebf754396623165f9dc0a29c2a48879f5Douglas Gregor template<class T> void apply(T x, void (*f)(T)) { f(x); } // expected-note 2 {{candidate template ignored: deduced conflicting types for parameter 'T'}}\ 55920dbba965a2f2a963313d94be3ff3d2b67ece7John McCall // expected-note {{no overload of 'temp2' matching 'void (*)(int)'}} 6eff92135d32039c9874dc356f3e93143af6069c1John McCall 7eff92135d32039c9874dc356f3e93143af6069c1John McCall template<class A> void temp(A); 8eff92135d32039c9874dc356f3e93143af6069c1John McCall void test0() { 9eff92135d32039c9874dc356f3e93143af6069c1John McCall // okay: deduce T=int from first argument, A=int during overload 10eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp); 11eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp<>); 12eff92135d32039c9874dc356f3e93143af6069c1John McCall 13eff92135d32039c9874dc356f3e93143af6069c1John McCall // okay: deduce T=int from first and second arguments 14eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp<int>); 15eff92135d32039c9874dc356f3e93143af6069c1John McCall 16eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduction failure: T=int from first, T=long from second 17eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp<long>); // expected-error {{no matching function for call to 'apply'}} 18eff92135d32039c9874dc356f3e93143af6069c1John McCall } 19eff92135d32039c9874dc356f3e93143af6069c1John McCall 20eff92135d32039c9874dc356f3e93143af6069c1John McCall void over(int); 21eff92135d32039c9874dc356f3e93143af6069c1John McCall int over(long); 22eff92135d32039c9874dc356f3e93143af6069c1John McCall 23eff92135d32039c9874dc356f3e93143af6069c1John McCall void test1() { 24eff92135d32039c9874dc356f3e93143af6069c1John McCall // okay: deductions match 25eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &over); 26eff92135d32039c9874dc356f3e93143af6069c1John McCall 27eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduction failure: deduced T=long from first argument, T=int from second 28eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0L, &over); // expected-error {{no matching function for call to 'apply'}} 29eff92135d32039c9874dc356f3e93143af6069c1John McCall } 30eff92135d32039c9874dc356f3e93143af6069c1John McCall 31eff92135d32039c9874dc356f3e93143af6069c1John McCall void over(short); 32eff92135d32039c9874dc356f3e93143af6069c1John McCall 33eff92135d32039c9874dc356f3e93143af6069c1John McCall void test2() { 34eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduce T=int from first arg, second arg is undeduced context, 35eff92135d32039c9874dc356f3e93143af6069c1John McCall // pick correct overload of 'over' during overload resolution for 'apply' 36eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &over); 37eff92135d32039c9874dc356f3e93143af6069c1John McCall } 38eff92135d32039c9874dc356f3e93143af6069c1John McCall 39eff92135d32039c9874dc356f3e93143af6069c1John McCall template<class A, class B> B temp2(A); 40eff92135d32039c9874dc356f3e93143af6069c1John McCall void test3() { 41eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduce T=int from first arg, A=int B=void during overload resolution 42eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp2); 43eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp2<>); 44eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp2<int>); 45eff92135d32039c9874dc356f3e93143af6069c1John McCall 46eff92135d32039c9874dc356f3e93143af6069c1John McCall // overload failure 47eff92135d32039c9874dc356f3e93143af6069c1John McCall apply(0, &temp2<long>); // expected-error {{no matching function for call to 'apply'}} 48eff92135d32039c9874dc356f3e93143af6069c1John McCall } 49eff92135d32039c9874dc356f3e93143af6069c1John McCall} 50eff92135d32039c9874dc356f3e93143af6069c1John McCall 51eff92135d32039c9874dc356f3e93143af6069c1John McCallnamespace test1 { 52eff92135d32039c9874dc356f3e93143af6069c1John McCall template<class T> void invoke(void (*f)(T)) { f(T()); } // expected-note 6 {{couldn't infer template argument}} \ 53860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} 54eff92135d32039c9874dc356f3e93143af6069c1John McCall 55eff92135d32039c9874dc356f3e93143af6069c1John McCall template<class T> void temp(T); 56eff92135d32039c9874dc356f3e93143af6069c1John McCall void test0() { 57eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduction failure: overload has template => undeduced context 58eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp); // expected-error {{no matching function for call to 'invoke'}} 59eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp<>); // expected-error {{no matching function for call to 'invoke'}} 60eff92135d32039c9874dc356f3e93143af6069c1John McCall 61eff92135d32039c9874dc356f3e93143af6069c1John McCall // okay: full template-id 62eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp<int>); 63eff92135d32039c9874dc356f3e93143af6069c1John McCall } 64eff92135d32039c9874dc356f3e93143af6069c1John McCall 65eff92135d32039c9874dc356f3e93143af6069c1John McCall void over(int); 66eff92135d32039c9874dc356f3e93143af6069c1John McCall int over(long); 67eff92135d32039c9874dc356f3e93143af6069c1John McCall 68eff92135d32039c9874dc356f3e93143af6069c1John McCall void test1() { 69eff92135d32039c9874dc356f3e93143af6069c1John McCall // okay: only one overload matches 70eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&over); 71eff92135d32039c9874dc356f3e93143af6069c1John McCall } 72eff92135d32039c9874dc356f3e93143af6069c1John McCall 73eff92135d32039c9874dc356f3e93143af6069c1John McCall void over(short); 74eff92135d32039c9874dc356f3e93143af6069c1John McCall 75eff92135d32039c9874dc356f3e93143af6069c1John McCall void test2() { 76eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduction failure: overload has multiple matches => undeduced context 77eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&over); // expected-error {{no matching function for call to 'invoke'}} 78eff92135d32039c9874dc356f3e93143af6069c1John McCall } 79eff92135d32039c9874dc356f3e93143af6069c1John McCall 80eff92135d32039c9874dc356f3e93143af6069c1John McCall template<class A, class B> B temp2(A); 81eff92135d32039c9874dc356f3e93143af6069c1John McCall void test3() { 82eff92135d32039c9874dc356f3e93143af6069c1John McCall // deduction failure: overload has template => undeduced context 83eff92135d32039c9874dc356f3e93143af6069c1John McCall // (even though partial application temp2<int> could in theory 84eff92135d32039c9874dc356f3e93143af6069c1John McCall // let us infer T=int) 85eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp2); // expected-error {{no matching function for call to 'invoke'}} 86eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp2<>); // expected-error {{no matching function for call to 'invoke'}} 87eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp2<int>); // expected-error {{no matching function for call to 'invoke'}} 88eff92135d32039c9874dc356f3e93143af6069c1John McCall 89eff92135d32039c9874dc356f3e93143af6069c1John McCall // okay: full template-id 90eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp2<int, void>); 91eff92135d32039c9874dc356f3e93143af6069c1John McCall 92eff92135d32039c9874dc356f3e93143af6069c1John McCall // overload failure 93eff92135d32039c9874dc356f3e93143af6069c1John McCall invoke(&temp2<int, int>); // expected-error {{no matching function for call to 'invoke'}} 94eff92135d32039c9874dc356f3e93143af6069c1John McCall } 95eff92135d32039c9874dc356f3e93143af6069c1John McCall} 9675f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor 9775f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregornamespace rdar8360106 { 9875f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor template<typename R, typename T> void f0(R (*)(T), T); 9975f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor template<typename R, typename T> void f1(R (&)(T) , T); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}} 10075f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor template<typename R, typename T> void f2(R (* const&)(T), T); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}} 10175f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor 10275f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor int g(int); 10375f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor int g(int, int); 10475f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor 10575f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor void h() { 10675f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor f0(g, 1); 10775f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor f0(&g, 1); 10875f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor f1(g, 1); 10975f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor f1(&g, 1); // expected-error{{no matching function for call to 'f1'}} 11075f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor f2(g, 1); // expected-error{{no matching function for call to 'f2'}} 11175f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor f2(&g, 1); 11275f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor } 11375f21af57f3dce1577d6c27bbe7bb45b49ced732Douglas Gregor} 114860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor 115860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregornamespace PR11713 { 116860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor template<typename T> 117860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor int f(int, int, int); 118860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor 119860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor template<typename T> 120860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor float f(float, float); 121860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor 122860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor template<typename R, typename B1, typename B2, typename A1, typename A2> 123860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor R& g(R (*)(B1, B2), A1, A2); 124860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor 125860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor void h() { 126860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor float &fr = g(f<int>, 1, 2); 127860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor } 128860d9b780b54f56cd27e16620196d213385d31f7Douglas Gregor} 129