Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Charles Li | 542f04c | 2015-11-11 19:34:47 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Douglas Gregor | e81f58e | 2010-11-08 03:40:48 +0000 | [diff] [blame] | 4 | int f(double); // expected-note{{candidate function}} |
| 5 | int f(int); // expected-note{{candidate function}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 6 | |
| 7 | int (*pfd)(double) = f; // selects f(double) |
| 8 | int (*pfd2)(double) = &f; // selects f(double) |
| 9 | int (*pfd3)(double) = ((&((f)))); // selects f(double) |
| 10 | int (*pfi)(int) = &f; // selects f(int) |
| 11 | // FIXME: This error message is not very good. We need to keep better |
| 12 | // track of what went wrong when the implicit conversion failed to |
| 13 | // give a better error message here. |
Douglas Gregor | e81f58e | 2010-11-08 03:40:48 +0000 | [diff] [blame] | 14 | int (*pfe)(...) = &f; // expected-error{{address of overloaded function 'f' does not match required type 'int (...)'}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 15 | int (&rfi)(int) = f; // selects f(int) |
| 16 | int (&rfd)(double) = f; // selects f(double) |
| 17 | |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 18 | void g(int (*fp)(int)); // expected-note{{candidate function}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 19 | void g(int (*fp)(float)); |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 20 | void g(int (*fp)(double)); // expected-note{{candidate function}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 21 | |
| 22 | int g1(int); |
| 23 | int g1(char); |
| 24 | |
| 25 | int g2(int); |
| 26 | int g2(double); |
| 27 | |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 28 | template<typename T> T g3(T); |
| 29 | int g3(int); |
| 30 | int g3(char); |
| 31 | |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 32 | void g_test() { |
| 33 | g(g1); |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 34 | g(g2); // expected-error{{call to 'g' is ambiguous}} |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 35 | g(g3); |
| 36 | } |
| 37 | |
| 38 | template<typename T> T h1(T); |
| 39 | template<typename R, typename A1> R h1(A1); |
Douglas Gregor | 2e0807c | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 40 | int h1(char); |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | 2e0807c | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 42 | void ha(int (*fp)(int)); |
| 43 | void hb(int (*fp)(double)); |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 44 | |
| 45 | void h_test() { |
Douglas Gregor | 2e0807c | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 46 | ha(h1); |
| 47 | hb(h1); |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 48 | } |
Anders Carlsson | 6c966c4 | 2009-10-07 22:26:29 +0000 | [diff] [blame] | 49 | |
| 50 | struct A { }; |
| 51 | void f(void (*)(A *)); |
| 52 | |
| 53 | struct B |
| 54 | { |
| 55 | void g() { f(d); } |
| 56 | void d(void *); |
| 57 | static void d(A *); |
| 58 | }; |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 59 | |
| 60 | struct C { |
| 61 | C &getC() { |
David Blaikie | e5323aa | 2013-06-21 23:54:45 +0000 | [diff] [blame] | 62 | return makeAC; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 63 | } |
| 64 | |
David Blaikie | 6df859d8 | 2013-06-04 00:28:46 +0000 | [diff] [blame] | 65 | // FIXME: filter by const so we can unambiguously suggest '()' & point to just the one candidate, probably |
| 66 | C &makeAC(); // expected-note{{possible target for call}} |
| 67 | const C &makeAC() const; // expected-note{{possible target for call}} |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 68 | |
| 69 | static void f(); // expected-note{{candidate function}} |
| 70 | static void f(int); // expected-note{{candidate function}} |
| 71 | |
| 72 | void g() { |
| 73 | int (&fp)() = f; // expected-error{{address of overloaded function 'f' does not match required type 'int ()'}} |
| 74 | } |
David Blaikie | e5323aa | 2013-06-21 23:54:45 +0000 | [diff] [blame] | 75 | |
| 76 | template<typename T> |
| 77 | void q1(int); // expected-note{{possible target for call}} |
| 78 | template<typename T> |
| 79 | void q2(T t = T()); // expected-note{{possible target for call}} |
| 80 | template<typename T> |
| 81 | void q3(); // expected-note{{possible target for call}} |
| 82 | template<typename T1, typename T2> |
| 83 | void q4(); // expected-note{{possible target for call}} |
Charles Li | 542f04c | 2015-11-11 19:34:47 +0000 | [diff] [blame] | 84 | template<typename T1 = int> |
| 85 | #if __cplusplus <= 199711L // C++03 or earlier modes |
| 86 | // expected-warning@-2{{default template arguments for a function template are a C++11 extension}} |
| 87 | #endif |
David Blaikie | e5323aa | 2013-06-21 23:54:45 +0000 | [diff] [blame] | 88 | void q5(); // expected-note{{possible target for call}} |
| 89 | |
| 90 | void h() { |
| 91 | // Do not suggest '()' since an int argument is required |
Alp Toker | 6ed7251 | 2013-12-14 01:07:05 +0000 | [diff] [blame] | 92 | q1<int>; // expected-error-re{{reference to non-static member function must be called{{$}}}} |
David Blaikie | e5323aa | 2013-06-21 23:54:45 +0000 | [diff] [blame] | 93 | // Suggest '()' since there's a default value for the only argument & the |
| 94 | // type argument is already provided |
| 95 | q2<int>; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} |
| 96 | // Suggest '()' since no arguments are required & the type argument is |
| 97 | // already provided |
| 98 | q3<int>; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} |
| 99 | // Do not suggest '()' since another type argument is required |
Alp Toker | 6ed7251 | 2013-12-14 01:07:05 +0000 | [diff] [blame] | 100 | q4<int>; // expected-error-re{{reference to non-static member function must be called{{$}}}} |
David Blaikie | e5323aa | 2013-06-21 23:54:45 +0000 | [diff] [blame] | 101 | // Suggest '()' since the type parameter has a default value |
| 102 | q5; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} |
| 103 | } |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 104 | }; |
John McCall | 8c12dc4 | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 105 | |
| 106 | // PR6886 |
| 107 | namespace test0 { |
| 108 | void myFunction(void (*)(void *)); |
| 109 | |
| 110 | class Foo { |
| 111 | void foo(); |
| 112 | |
| 113 | static void bar(void*); |
| 114 | static void bar(); |
| 115 | }; |
| 116 | |
| 117 | void Foo::foo() { |
| 118 | myFunction(bar); |
| 119 | } |
| 120 | } |
Eli Friedman | 7fd5544 | 2010-08-24 05:23:20 +0000 | [diff] [blame] | 121 | |
| 122 | namespace PR7971 { |
| 123 | struct S { |
| 124 | void g() { |
| 125 | f(&g); |
| 126 | } |
| 127 | void f(bool (*)(int, char)); |
| 128 | static bool g(int, char); |
| 129 | }; |
| 130 | } |
Douglas Gregor | bdd7b23 | 2010-09-12 08:16:09 +0000 | [diff] [blame] | 131 | |
| 132 | namespace PR8033 { |
George Burgess IV | 5f2ef45 | 2015-10-12 18:40:58 +0000 | [diff] [blame] | 133 | template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} |
| 134 | template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}} |
| 135 | int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} |
Douglas Gregor | bdd7b23 | 2010-09-12 08:16:09 +0000 | [diff] [blame] | 136 | } |
Douglas Gregor | 4ed49f3 | 2010-09-29 21:14:36 +0000 | [diff] [blame] | 137 | |
| 138 | namespace PR8196 { |
| 139 | template <typename T> struct mcdata { |
| 140 | typedef int result_type; |
| 141 | }; |
| 142 | template <class T> |
| 143 | typename mcdata<T>::result_type wrap_mean(mcdata<T> const&); |
| 144 | void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}} |
| 145 | void f() { |
| 146 | add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}} |
| 147 | } |
| 148 | } |
Douglas Gregor | bcd6253 | 2010-11-08 15:20:28 +0000 | [diff] [blame] | 149 | |
| 150 | namespace PR7425 { |
| 151 | template<typename T> |
| 152 | void foo() |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | struct B |
| 157 | { |
| 158 | template<typename T> |
| 159 | B(const T&) |
| 160 | { |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | void bar(const B& b) |
| 165 | { |
| 166 | } |
| 167 | |
| 168 | void bar2(const B& b = foo<int>) |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | void test(int argc, char** argv) |
| 173 | { |
| 174 | bar(foo<int>); |
| 175 | bar2(); |
| 176 | } |
| 177 | } |
Richard Trieu | caff247 | 2011-11-23 22:32:32 +0000 | [diff] [blame] | 178 | |
| 179 | namespace test1 { |
| 180 | void fun(int x) {} |
| 181 | |
| 182 | void parameter_number() { |
| 183 | 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 | void (*ptr2)(int, int); |
| 185 | ptr2 = &fun; // expected-error {{assigning to 'void (*)(int, int)' from incompatible type 'void (*)(int)': different number of parameters (2 vs 1)}} |
| 186 | } |
| 187 | |
| 188 | void parameter_mismatch() { |
Richard Trieu | 96ed5b6 | 2011-12-13 23:19:45 +0000 | [diff] [blame] | 189 | 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 Trieu | caff247 | 2011-11-23 22:32:32 +0000 | [diff] [blame] | 190 | void (*ptr2)(double); |
| 191 | ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}} |
| 192 | } |
| 193 | |
| 194 | void return_type_test() { |
| 195 | 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 | int (*ptr2)(int); |
| 197 | ptr2 = &fun; // expected-error {{assigning to 'int (*)(int)' from incompatible type 'void (*)(int)': different return type ('int' vs 'void')}} |
| 198 | } |
| 199 | |
| 200 | int foo(double x, double y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 201 | int foo(int x, int y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 202 | int foo(double x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'double')}} |
| 203 | double foo(float x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 204 | double foo(int x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 205 | double foo(float x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'float')}} |
| 206 | double foo(int x) {return 0;} // expected-note {{candidate function has different return type ('int' expected but has 'double')}} |
| 207 | |
| 208 | int (*ptr)(int) = &foo; // expected-error {{address of overloaded function 'foo' does not match required type 'int (int)'}} |
| 209 | |
| 210 | struct Qualifiers { |
| 211 | void N() {}; |
| 212 | void C() const {}; |
| 213 | void V() volatile {}; |
| 214 | void R() __restrict {}; |
| 215 | void CV() const volatile {}; |
| 216 | void CR() const __restrict {}; |
| 217 | void VR() volatile __restrict {}; |
| 218 | void CVR() const volatile __restrict {}; |
| 219 | }; |
| 220 | |
| 221 | |
| 222 | void QualifierTest() { |
| 223 | void (Qualifiers::*X)(); |
Alp Toker | 6ed7251 | 2013-12-14 01:07:05 +0000 | [diff] [blame] | 224 | 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 | 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)}} |
Jacques Pienaar | b92e7a9 | 2015-03-03 23:58:09 +0000 | [diff] [blame] | 226 | 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)}} |
Alp Toker | 6ed7251 | 2013-12-14 01:07:05 +0000 | [diff] [blame] | 227 | 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)}} |
Jacques Pienaar | b92e7a9 | 2015-03-03 23:58:09 +0000 | [diff] [blame] | 228 | 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 | 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 | 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)}} |
Richard Trieu | caff247 | 2011-11-23 22:32:32 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | struct Dummy { |
| 234 | void N() {}; |
| 235 | }; |
| 236 | |
Alp Toker | 6ed7251 | 2013-12-14 01:07:05 +0000 | [diff] [blame] | 237 | 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')}} |
Richard Trieu | caff247 | 2011-11-23 22:32:32 +0000 | [diff] [blame] | 238 | } |
Eli Friedman | 544c956 | 2013-07-08 23:35:04 +0000 | [diff] [blame] | 239 | |
| 240 | template <typename T> class PR16561 { |
| 241 | virtual bool f() { if (f) {} return false; } // expected-error {{reference to non-static member function must be called}} |
| 242 | }; |