blob: 096f74823a4298cf86366fa2cfd877d675ba47da [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor8e960432010-11-08 03:40:48 +00002int f(double); // expected-note{{candidate function}}
3int f(int); // expected-note{{candidate function}}
Douglas Gregor904eed32008-11-10 20:40:00 +00004
5int (*pfd)(double) = f; // selects f(double)
6int (*pfd2)(double) = &f; // selects f(double)
7int (*pfd3)(double) = ((&((f)))); // selects f(double)
8int (*pfi)(int) = &f; // selects f(int)
9// FIXME: This error message is not very good. We need to keep better
10// track of what went wrong when the implicit conversion failed to
11// give a better error message here.
Douglas Gregor8e960432010-11-08 03:40:48 +000012int (*pfe)(...) = &f; // expected-error{{address of overloaded function 'f' does not match required type 'int (...)'}}
Douglas Gregor904eed32008-11-10 20:40:00 +000013int (&rfi)(int) = f; // selects f(int)
14int (&rfd)(double) = f; // selects f(double)
15
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000016void g(int (*fp)(int)); // expected-note{{candidate function}}
Douglas Gregor904eed32008-11-10 20:40:00 +000017void g(int (*fp)(float));
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000018void g(int (*fp)(double)); // expected-note{{candidate function}}
Douglas Gregor904eed32008-11-10 20:40:00 +000019
20int g1(int);
21int g1(char);
22
23int g2(int);
24int g2(double);
25
Douglas Gregord173b202009-09-14 22:02:01 +000026template<typename T> T g3(T);
27int g3(int);
28int g3(char);
29
Douglas Gregor904eed32008-11-10 20:40:00 +000030void g_test() {
31 g(g1);
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000032 g(g2); // expected-error{{call to 'g' is ambiguous}}
Douglas Gregord173b202009-09-14 22:02:01 +000033 g(g3);
34}
35
36template<typename T> T h1(T);
37template<typename R, typename A1> R h1(A1);
Douglas Gregor60d92312009-09-14 22:31:20 +000038int h1(char);
Douglas Gregord173b202009-09-14 22:02:01 +000039
Douglas Gregor60d92312009-09-14 22:31:20 +000040void ha(int (*fp)(int));
41void hb(int (*fp)(double));
Douglas Gregord173b202009-09-14 22:02:01 +000042
43void h_test() {
Douglas Gregor60d92312009-09-14 22:31:20 +000044 ha(h1);
45 hb(h1);
Douglas Gregor904eed32008-11-10 20:40:00 +000046}
Anders Carlsson6e8f5502009-10-07 22:26:29 +000047
48struct A { };
49void f(void (*)(A *));
50
51struct B
52{
53 void g() { f(d); }
54 void d(void *);
55 static void d(A *);
56};
Douglas Gregor1a8cf732010-04-14 23:11:21 +000057
58struct C {
59 C &getC() {
John McCall5acb0c92011-10-17 18:40:02 +000060 return makeAC; // expected-error{{reference to non-static member function must be called}}
Douglas Gregor1a8cf732010-04-14 23:11:21 +000061 }
62
John McCall864c0412011-04-26 20:42:42 +000063 C &makeAC();
64 const C &makeAC() const;
Douglas Gregor1a8cf732010-04-14 23:11:21 +000065
66 static void f(); // expected-note{{candidate function}}
67 static void f(int); // expected-note{{candidate function}}
68
69 void g() {
70 int (&fp)() = f; // expected-error{{address of overloaded function 'f' does not match required type 'int ()'}}
71 }
72};
John McCalle9ee23e2010-04-22 18:44:12 +000073
74// PR6886
75namespace test0 {
76 void myFunction(void (*)(void *));
77
78 class Foo {
79 void foo();
80
81 static void bar(void*);
82 static void bar();
83 };
84
85 void Foo::foo() {
86 myFunction(bar);
87 }
88}
Eli Friedmanfb3bb312010-08-24 05:23:20 +000089
90namespace PR7971 {
91 struct S {
92 void g() {
93 f(&g);
94 }
95 void f(bool (*)(int, char));
96 static bool g(int, char);
97 };
98}
Douglas Gregor78c057e2010-09-12 08:16:09 +000099
100namespace PR8033 {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +0000101 template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} \
102 // expected-note{{candidate function}}
103 template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}} \
104 // expected-note{{candidate function}}
Douglas Gregor78c057e2010-09-12 08:16:09 +0000105 int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \
Douglas Gregor8e960432010-11-08 03:40:48 +0000106 // expected-error{{address of overloaded function 'f' is ambiguous}}
Douglas Gregor78c057e2010-09-12 08:16:09 +0000107
108}
Douglas Gregorfbb6fad2010-09-29 21:14:36 +0000109
110namespace PR8196 {
111 template <typename T> struct mcdata {
112 typedef int result_type;
113 };
114 template <class T>
115 typename mcdata<T>::result_type wrap_mean(mcdata<T> const&);
116 void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}}
117 void f() {
118 add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}}
119 }
120}
Douglas Gregor3afb9772010-11-08 15:20:28 +0000121
122namespace PR7425 {
123 template<typename T>
124 void foo()
125 {
126 }
127
128 struct B
129 {
130 template<typename T>
131 B(const T&)
132 {
133 }
134 };
135
136 void bar(const B& b)
137 {
138 }
139
140 void bar2(const B& b = foo<int>)
141 {
142 }
143
144 void test(int argc, char** argv)
145 {
146 bar(foo<int>);
147 bar2();
148 }
149}
Richard Trieu6efd4c52011-11-23 22:32:32 +0000150
151namespace test1 {
152 void fun(int x) {}
153
154 void parameter_number() {
155 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)}}
156 void (*ptr2)(int, int);
157 ptr2 = &fun; // expected-error {{assigning to 'void (*)(int, int)' from incompatible type 'void (*)(int)': different number of parameters (2 vs 1)}}
158 }
159
160 void parameter_mismatch() {
Richard Trieua6dc7ef2011-12-13 23:19:45 +0000161 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')}}
Richard Trieu6efd4c52011-11-23 22:32:32 +0000162 void (*ptr2)(double);
163 ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}}
164 }
165
166 void return_type_test() {
167 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')}}
168 int (*ptr2)(int);
169 ptr2 = &fun; // expected-error {{assigning to 'int (*)(int)' from incompatible type 'void (*)(int)': different return type ('int' vs 'void')}}
170 }
171
172 int foo(double x, double y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
173 int foo(int x, int y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
174 int foo(double x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'double')}}
175 double foo(float x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
176 double foo(int x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}}
177 double foo(float x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'float')}}
178 double foo(int x) {return 0;} // expected-note {{candidate function has different return type ('int' expected but has 'double')}}
179
180 int (*ptr)(int) = &foo; // expected-error {{address of overloaded function 'foo' does not match required type 'int (int)'}}
181
182 struct Qualifiers {
183 void N() {};
184 void C() const {};
185 void V() volatile {};
186 void R() __restrict {};
187 void CV() const volatile {};
188 void CR() const __restrict {};
189 void VR() volatile __restrict {};
190 void CVR() const volatile __restrict {};
191 };
192
193
194 void QualifierTest() {
195 void (Qualifiers::*X)();
196 X = &Qualifiers::C; // expected-error {{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() const': different qualifiers (none vs const)}}
197 X = &Qualifiers::V; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() volatile': different qualifiers (none vs volatile)}}
198 X = &Qualifiers::R; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() restrict': different qualifiers (none vs restrict)}}
199 X = &Qualifiers::CV; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() const volatile': different qualifiers (none vs const and volatile)}}
200 X = &Qualifiers::CR; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() const restrict': different qualifiers (none vs const and restrict)}}
201 X = &Qualifiers::VR; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() volatile restrict': different qualifiers (none vs volatile and restrict)}}
202 X = &Qualifiers::CVR; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() const volatile restrict': different qualifiers (none vs const, volatile, and restrict)}}
203 }
204
205 struct Dummy {
206 void N() {};
207 };
208
209 void (Qualifiers::*X)() = &Dummy::N; // expected-error{{cannot initialize a variable of type 'void (test1::Qualifiers::*)()' with an rvalue of type 'void (test1::Dummy::*)()': different classes ('test1::Qualifiers' vs 'test1::Dummy')}}
210}