p6.cpp revision 5920dbba965a2f2a963313d94be3ff3d2b67ece7
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3namespace test0 {
4  // FIXME: this second note is horrible.
5  template<class T> void apply(T x, void (*f)(T)) { f(x); } // expected-note 2 {{failed template argument deduction}}\
6  // expected-note {{no overload of 'temp2' matching 'void (*)(int)'}}
7
8  template<class A> void temp(A);
9  void test0() {
10    // okay: deduce T=int from first argument, A=int during overload
11    apply(0, &temp);
12    apply(0, &temp<>);
13
14    // okay: deduce T=int from first and second arguments
15    apply(0, &temp<int>);
16
17    // deduction failure: T=int from first, T=long from second
18    apply(0, &temp<long>); // expected-error {{no matching function for call to 'apply'}}
19  }
20
21  void over(int);
22  int over(long);
23
24  void test1() {
25    // okay: deductions match
26    apply(0, &over);
27
28    // deduction failure: deduced T=long from first argument, T=int from second
29    apply(0L, &over); // expected-error {{no matching function for call to 'apply'}}
30  }
31
32  void over(short);
33
34  void test2() {
35    // deduce T=int from first arg, second arg is undeduced context,
36    // pick correct overload of 'over' during overload resolution for 'apply'
37    apply(0, &over);
38  }
39
40  template<class A, class B> B temp2(A);
41  void test3() {
42    // deduce T=int from first arg, A=int B=void during overload resolution
43    apply(0, &temp2);
44    apply(0, &temp2<>);
45    apply(0, &temp2<int>);
46
47    // overload failure
48    apply(0, &temp2<long>); // expected-error {{no matching function for call to 'apply'}}
49  }
50}
51
52namespace test1 {
53  template<class T> void invoke(void (*f)(T)) { f(T()); } // expected-note 6 {{couldn't infer template argument}} \
54  // expected-note {{failed template argument deduction}}
55
56  template<class T> void temp(T);
57  void test0() {
58    // deduction failure: overload has template => undeduced context
59    invoke(&temp); // expected-error {{no matching function for call to 'invoke'}}
60    invoke(&temp<>); // expected-error {{no matching function for call to 'invoke'}}
61
62    // okay: full template-id
63    invoke(&temp<int>);
64  }
65
66  void over(int);
67  int over(long);
68
69  void test1() {
70    // okay: only one overload matches
71    invoke(&over);
72  }
73
74  void over(short);
75
76  void test2() {
77    // deduction failure: overload has multiple matches => undeduced context
78    invoke(&over); // expected-error {{no matching function for call to 'invoke'}}
79  }
80
81  template<class A, class B> B temp2(A);
82  void test3() {
83    // deduction failure: overload has template => undeduced context
84    // (even though partial application temp2<int> could in theory
85    // let us infer T=int)
86    invoke(&temp2); // expected-error {{no matching function for call to 'invoke'}}
87    invoke(&temp2<>); // expected-error {{no matching function for call to 'invoke'}}
88    invoke(&temp2<int>); // expected-error {{no matching function for call to 'invoke'}}
89
90    // okay: full template-id
91    invoke(&temp2<int, void>);
92
93    // overload failure
94    invoke(&temp2<int, int>); // expected-error {{no matching function for call to 'invoke'}}
95  }
96}
97