1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4*67e74705SXin Li int f(double); // expected-note{{candidate function}}
5*67e74705SXin Li int f(int); // expected-note{{candidate function}}
6*67e74705SXin Li
7*67e74705SXin Li int (*pfd)(double) = f; // selects f(double)
8*67e74705SXin Li int (*pfd2)(double) = &f; // selects f(double)
9*67e74705SXin Li int (*pfd3)(double) = ((&((f)))); // selects f(double)
10*67e74705SXin Li int (*pfi)(int) = &f; // selects f(int)
11*67e74705SXin Li // FIXME: This error message is not very good. We need to keep better
12*67e74705SXin Li // track of what went wrong when the implicit conversion failed to
13*67e74705SXin Li // give a better error message here.
14*67e74705SXin Li int (*pfe)(...) = &f; // expected-error{{address of overloaded function 'f' does not match required type 'int (...)'}}
15*67e74705SXin Li int (&rfi)(int) = f; // selects f(int)
16*67e74705SXin Li int (&rfd)(double) = f; // selects f(double)
17*67e74705SXin Li
18*67e74705SXin Li void g(int (*fp)(int)); // expected-note{{candidate function}}
19*67e74705SXin Li void g(int (*fp)(float));
20*67e74705SXin Li void g(int (*fp)(double)); // expected-note{{candidate function}}
21*67e74705SXin Li
22*67e74705SXin Li int g1(int);
23*67e74705SXin Li int g1(char);
24*67e74705SXin Li
25*67e74705SXin Li int g2(int);
26*67e74705SXin Li int g2(double);
27*67e74705SXin Li
28*67e74705SXin Li template<typename T> T g3(T);
29*67e74705SXin Li int g3(int);
30*67e74705SXin Li int g3(char);
31*67e74705SXin Li
g_test()32*67e74705SXin Li void g_test() {
33*67e74705SXin Li g(g1);
34*67e74705SXin Li g(g2); // expected-error{{call to 'g' is ambiguous}}
35*67e74705SXin Li g(g3);
36*67e74705SXin Li }
37*67e74705SXin Li
38*67e74705SXin Li template<typename T> T h1(T);
39*67e74705SXin Li template<typename R, typename A1> R h1(A1);
40*67e74705SXin Li int h1(char);
41*67e74705SXin Li
42*67e74705SXin Li void ha(int (*fp)(int));
43*67e74705SXin Li void hb(int (*fp)(double));
44*67e74705SXin Li
h_test()45*67e74705SXin Li void h_test() {
46*67e74705SXin Li ha(h1);
47*67e74705SXin Li hb(h1);
48*67e74705SXin Li }
49*67e74705SXin Li
50*67e74705SXin Li struct A { };
51*67e74705SXin Li void f(void (*)(A *));
52*67e74705SXin Li
53*67e74705SXin Li struct B
54*67e74705SXin Li {
gB55*67e74705SXin Li void g() { f(d); }
56*67e74705SXin Li void d(void *);
57*67e74705SXin Li static void d(A *);
58*67e74705SXin Li };
59*67e74705SXin Li
60*67e74705SXin Li struct C {
getCC61*67e74705SXin Li C &getC() {
62*67e74705SXin Li return makeAC; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}}
63*67e74705SXin Li }
64*67e74705SXin Li
65*67e74705SXin Li // FIXME: filter by const so we can unambiguously suggest '()' & point to just the one candidate, probably
66*67e74705SXin Li C &makeAC(); // expected-note{{possible target for call}}
67*67e74705SXin Li const C &makeAC() const; // expected-note{{possible target for call}}
68*67e74705SXin Li
69*67e74705SXin Li static void f(); // expected-note{{candidate function}}
70*67e74705SXin Li static void f(int); // expected-note{{candidate function}}
71*67e74705SXin Li
gC72*67e74705SXin Li void g() {
73*67e74705SXin Li int (&fp)() = f; // expected-error{{address of overloaded function 'f' does not match required type 'int ()'}}
74*67e74705SXin Li }
75*67e74705SXin Li
76*67e74705SXin Li template<typename T>
77*67e74705SXin Li void q1(int); // expected-note{{possible target for call}}
78*67e74705SXin Li template<typename T>
79*67e74705SXin Li void q2(T t = T()); // expected-note{{possible target for call}}
80*67e74705SXin Li template<typename T>
81*67e74705SXin Li void q3(); // expected-note{{possible target for call}}
82*67e74705SXin Li template<typename T1, typename T2>
83*67e74705SXin Li void q4(); // expected-note{{possible target for call}}
84*67e74705SXin Li template<typename T1 = int>
85*67e74705SXin Li #if __cplusplus <= 199711L // C++03 or earlier modes
86*67e74705SXin Li // expected-warning@-2{{default template arguments for a function template are a C++11 extension}}
87*67e74705SXin Li #endif
88*67e74705SXin Li void q5(); // expected-note{{possible target for call}}
89*67e74705SXin Li
hC90*67e74705SXin Li void h() {
91*67e74705SXin Li // Do not suggest '()' since an int argument is required
92*67e74705SXin Li q1<int>; // expected-error-re{{reference to non-static member function must be called{{$}}}}
93*67e74705SXin Li // Suggest '()' since there's a default value for the only argument & the
94*67e74705SXin Li // type argument is already provided
95*67e74705SXin Li q2<int>; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}}
96*67e74705SXin Li // Suggest '()' since no arguments are required & the type argument is
97*67e74705SXin Li // already provided
98*67e74705SXin Li q3<int>; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}}
99*67e74705SXin Li // Do not suggest '()' since another type argument is required
100*67e74705SXin Li q4<int>; // expected-error-re{{reference to non-static member function must be called{{$}}}}
101*67e74705SXin Li // Suggest '()' since the type parameter has a default value
102*67e74705SXin Li q5; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}}
103*67e74705SXin Li }
104*67e74705SXin Li };
105*67e74705SXin Li
106*67e74705SXin Li // PR6886
107*67e74705SXin Li namespace test0 {
108*67e74705SXin Li void myFunction(void (*)(void *));
109*67e74705SXin Li
110*67e74705SXin Li class Foo {
111*67e74705SXin Li void foo();
112*67e74705SXin Li
113*67e74705SXin Li static void bar(void*);
114*67e74705SXin Li static void bar();
115*67e74705SXin Li };
116*67e74705SXin Li
foo()117*67e74705SXin Li void Foo::foo() {
118*67e74705SXin Li myFunction(bar);
119*67e74705SXin Li }
120*67e74705SXin Li }
121*67e74705SXin Li
122*67e74705SXin Li namespace PR7971 {
123*67e74705SXin Li struct S {
gPR7971::S124*67e74705SXin Li void g() {
125*67e74705SXin Li f(&g);
126*67e74705SXin Li }
127*67e74705SXin Li void f(bool (*)(int, char));
128*67e74705SXin Li static bool g(int, char);
129*67e74705SXin Li };
130*67e74705SXin Li }
131*67e74705SXin Li
132*67e74705SXin Li namespace PR8033 {
133*67e74705SXin Li template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}}
134*67e74705SXin Li template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}}
135*67e74705SXin Li int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}}
136*67e74705SXin Li }
137*67e74705SXin Li
138*67e74705SXin Li namespace PR8196 {
139*67e74705SXin Li template <typename T> struct mcdata {
140*67e74705SXin Li typedef int result_type;
141*67e74705SXin Li };
142*67e74705SXin Li template <class T>
143*67e74705SXin Li typename mcdata<T>::result_type wrap_mean(mcdata<T> const&);
144*67e74705SXin Li void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}}
f()145*67e74705SXin Li void f() {
146*67e74705SXin Li add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}}
147*67e74705SXin Li }
148*67e74705SXin Li }
149*67e74705SXin Li
150*67e74705SXin Li namespace PR7425 {
151*67e74705SXin Li template<typename T>
foo()152*67e74705SXin Li void foo()
153*67e74705SXin Li {
154*67e74705SXin Li }
155*67e74705SXin Li
156*67e74705SXin Li struct B
157*67e74705SXin Li {
158*67e74705SXin Li template<typename T>
BPR7425::B159*67e74705SXin Li B(const T&)
160*67e74705SXin Li {
161*67e74705SXin Li }
162*67e74705SXin Li };
163*67e74705SXin Li
bar(const B & b)164*67e74705SXin Li void bar(const B& b)
165*67e74705SXin Li {
166*67e74705SXin Li }
167*67e74705SXin Li
bar2(const B & b=foo<int>)168*67e74705SXin Li void bar2(const B& b = foo<int>)
169*67e74705SXin Li {
170*67e74705SXin Li }
171*67e74705SXin Li
test(int argc,char ** argv)172*67e74705SXin Li void test(int argc, char** argv)
173*67e74705SXin Li {
174*67e74705SXin Li bar(foo<int>);
175*67e74705SXin Li bar2();
176*67e74705SXin Li }
177*67e74705SXin Li }
178*67e74705SXin Li
179*67e74705SXin Li namespace test1 {
fun(int x)180*67e74705SXin Li void fun(int x) {}
181*67e74705SXin Li
parameter_number()182*67e74705SXin Li void parameter_number() {
183*67e74705SXin Li void (*ptr1)(int, int) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(int, int)' with an rvalue of type 'void (*)(int)': different number of parameters (2 vs 1)}}
184*67e74705SXin Li void (*ptr2)(int, int);
185*67e74705SXin Li ptr2 = &fun; // expected-error {{assigning to 'void (*)(int, int)' from incompatible type 'void (*)(int)': different number of parameters (2 vs 1)}}
186*67e74705SXin Li }
187*67e74705SXin Li
parameter_mismatch()188*67e74705SXin Li void parameter_mismatch() {
189*67e74705SXin Li void (*ptr1)(double) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(double)' with an rvalue of type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}}
190*67e74705SXin Li void (*ptr2)(double);
191*67e74705SXin Li ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}}
192*67e74705SXin Li }
193*67e74705SXin Li
return_type_test()194*67e74705SXin Li void return_type_test() {
195*67e74705SXin Li int (*ptr1)(int) = &fun; // expected-error {{cannot initialize a variable of type 'int (*)(int)' with an rvalue of type 'void (*)(int)': different return type ('int' vs 'void')}}
196*67e74705SXin Li int (*ptr2)(int);
197*67e74705SXin Li ptr2 = &fun; // expected-error {{assigning to 'int (*)(int)' from incompatible type 'void (*)(int)': different return type ('int' vs 'void')}}
198*67e74705SXin Li }
199*67e74705SXin Li
foo(double x,double y)200*67e74705SXin Li int foo(double x, double y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
foo(int x,int y)201*67e74705SXin Li int foo(int x, int y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
foo(double x)202*67e74705SXin Li int foo(double x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'double')}}
foo(float x,float y)203*67e74705SXin Li double foo(float x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
foo(int x,float y)204*67e74705SXin Li double foo(int x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
foo(float x)205*67e74705SXin Li double foo(float x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'float')}}
foo(int x)206*67e74705SXin Li double foo(int x) {return 0;} // expected-note {{candidate function has different return type ('int' expected but has 'double')}}
207*67e74705SXin Li
208*67e74705SXin Li int (*ptr)(int) = &foo; // expected-error {{address of overloaded function 'foo' does not match required type 'int (int)'}}
209*67e74705SXin Li
210*67e74705SXin Li struct Qualifiers {
Ntest1::Qualifiers211*67e74705SXin Li void N() {};
Ctest1::Qualifiers212*67e74705SXin Li void C() const {};
Vtest1::Qualifiers213*67e74705SXin Li void V() volatile {};
Rtest1::Qualifiers214*67e74705SXin Li void R() __restrict {};
CVtest1::Qualifiers215*67e74705SXin Li void CV() const volatile {};
CRtest1::Qualifiers216*67e74705SXin Li void CR() const __restrict {};
VRtest1::Qualifiers217*67e74705SXin Li void VR() volatile __restrict {};
CVRtest1::Qualifiers218*67e74705SXin Li void CVR() const volatile __restrict {};
219*67e74705SXin Li };
220*67e74705SXin Li
221*67e74705SXin Li
QualifierTest()222*67e74705SXin Li void QualifierTest() {
223*67e74705SXin Li void (Qualifiers::*X)();
224*67e74705SXin Li X = &Qualifiers::C; // expected-error-re {{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const': different qualifiers (none vs const)}}
225*67e74705SXin Li X = &Qualifiers::V; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} volatile': different qualifiers (none vs volatile)}}
226*67e74705SXin Li X = &Qualifiers::R; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} __restrict': different qualifiers (none vs restrict)}}
227*67e74705SXin Li X = &Qualifiers::CV; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const volatile': different qualifiers (none vs const and volatile)}}
228*67e74705SXin Li X = &Qualifiers::CR; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const __restrict': different qualifiers (none vs const and restrict)}}
229*67e74705SXin Li X = &Qualifiers::VR; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} volatile __restrict': different qualifiers (none vs volatile and restrict)}}
230*67e74705SXin Li X = &Qualifiers::CVR; // expected-error-re{{assigning to 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' from incompatible type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}} const volatile __restrict': different qualifiers (none vs const, volatile, and restrict)}}
231*67e74705SXin Li }
232*67e74705SXin Li
233*67e74705SXin Li struct Dummy {
Ntest1::Dummy234*67e74705SXin Li void N() {};
235*67e74705SXin Li };
236*67e74705SXin Li
237*67e74705SXin Li void (Qualifiers::*X)() = &Dummy::N; // expected-error-re{{cannot initialize a variable of type 'void (test1::Qualifiers::*)(){{( __attribute__\(\(thiscall\)\))?}}' with an rvalue of type 'void (test1::Dummy::*)(){{( __attribute__\(\(thiscall\)\))?}}': different classes ('test1::Qualifiers' vs 'test1::Dummy')}}
238*67e74705SXin Li }
239*67e74705SXin Li
240*67e74705SXin Li template <typename T> class PR16561 {
f()241*67e74705SXin Li virtual bool f() { if (f) {} return false; } // expected-error {{reference to non-static member function must be called}}
242*67e74705SXin Li };
243