Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | e81f58e | 2010-11-08 03:40:48 +0000 | [diff] [blame] | 2 | int f(double); // expected-note{{candidate function}} |
| 3 | int f(int); // expected-note{{candidate function}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 4 | |
| 5 | int (*pfd)(double) = f; // selects f(double) |
| 6 | int (*pfd2)(double) = &f; // selects f(double) |
| 7 | int (*pfd3)(double) = ((&((f)))); // selects f(double) |
| 8 | int (*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 Gregor | e81f58e | 2010-11-08 03:40:48 +0000 | [diff] [blame] | 12 | 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] | 13 | int (&rfi)(int) = f; // selects f(int) |
| 14 | int (&rfd)(double) = f; // selects f(double) |
| 15 | |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 16 | void g(int (*fp)(int)); // expected-note{{candidate function}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 17 | void g(int (*fp)(float)); |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 18 | void g(int (*fp)(double)); // expected-note{{candidate function}} |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 19 | |
| 20 | int g1(int); |
| 21 | int g1(char); |
| 22 | |
| 23 | int g2(int); |
| 24 | int g2(double); |
| 25 | |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 26 | template<typename T> T g3(T); |
| 27 | int g3(int); |
| 28 | int g3(char); |
| 29 | |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 30 | void g_test() { |
| 31 | g(g1); |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 32 | g(g2); // expected-error{{call to 'g' is ambiguous}} |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 33 | g(g3); |
| 34 | } |
| 35 | |
| 36 | template<typename T> T h1(T); |
| 37 | template<typename R, typename A1> R h1(A1); |
Douglas Gregor | 2e0807c | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 38 | int h1(char); |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | 2e0807c | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 40 | void ha(int (*fp)(int)); |
| 41 | void hb(int (*fp)(double)); |
Douglas Gregor | 48bc374 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 42 | |
| 43 | void h_test() { |
Douglas Gregor | 2e0807c | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 44 | ha(h1); |
| 45 | hb(h1); |
Douglas Gregor | cd695e5 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 46 | } |
Anders Carlsson | 6c966c4 | 2009-10-07 22:26:29 +0000 | [diff] [blame] | 47 | |
| 48 | struct A { }; |
| 49 | void f(void (*)(A *)); |
| 50 | |
| 51 | struct B |
| 52 | { |
| 53 | void g() { f(d); } |
| 54 | void d(void *); |
| 55 | static void d(A *); |
| 56 | }; |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 57 | |
| 58 | struct C { |
| 59 | C &getC() { |
David Blaikie | 6df859d8 | 2013-06-04 00:28:46 +0000 | [diff] [blame^] | 60 | return makeAC; // expected-error-re{{reference to non-static member function must be called$}} |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 61 | } |
| 62 | |
David Blaikie | 6df859d8 | 2013-06-04 00:28:46 +0000 | [diff] [blame^] | 63 | // FIXME: filter by const so we can unambiguously suggest '()' & point to just the one candidate, probably |
| 64 | C &makeAC(); // expected-note{{possible target for call}} |
| 65 | const C &makeAC() const; // expected-note{{possible target for call}} |
Douglas Gregor | 064fdb2 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 66 | |
| 67 | static void f(); // expected-note{{candidate function}} |
| 68 | static void f(int); // expected-note{{candidate function}} |
| 69 | |
| 70 | void g() { |
| 71 | int (&fp)() = f; // expected-error{{address of overloaded function 'f' does not match required type 'int ()'}} |
| 72 | } |
| 73 | }; |
John McCall | 8c12dc4 | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 74 | |
| 75 | // PR6886 |
| 76 | namespace test0 { |
| 77 | void myFunction(void (*)(void *)); |
| 78 | |
| 79 | class Foo { |
| 80 | void foo(); |
| 81 | |
| 82 | static void bar(void*); |
| 83 | static void bar(); |
| 84 | }; |
| 85 | |
| 86 | void Foo::foo() { |
| 87 | myFunction(bar); |
| 88 | } |
| 89 | } |
Eli Friedman | 7fd5544 | 2010-08-24 05:23:20 +0000 | [diff] [blame] | 90 | |
| 91 | namespace PR7971 { |
| 92 | struct S { |
| 93 | void g() { |
| 94 | f(&g); |
| 95 | } |
| 96 | void f(bool (*)(int, char)); |
| 97 | static bool g(int, char); |
| 98 | }; |
| 99 | } |
Douglas Gregor | bdd7b23 | 2010-09-12 08:16:09 +0000 | [diff] [blame] | 100 | |
| 101 | namespace PR8033 { |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 102 | template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} \ |
| 103 | // expected-note{{candidate function}} |
| 104 | template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}} \ |
| 105 | // expected-note{{candidate function}} |
Douglas Gregor | bdd7b23 | 2010-09-12 08:16:09 +0000 | [diff] [blame] | 106 | int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \ |
Douglas Gregor | e81f58e | 2010-11-08 03:40:48 +0000 | [diff] [blame] | 107 | // expected-error{{address of overloaded function 'f' is ambiguous}} |
Douglas Gregor | bdd7b23 | 2010-09-12 08:16:09 +0000 | [diff] [blame] | 108 | |
| 109 | } |
Douglas Gregor | 4ed49f3 | 2010-09-29 21:14:36 +0000 | [diff] [blame] | 110 | |
| 111 | namespace PR8196 { |
| 112 | template <typename T> struct mcdata { |
| 113 | typedef int result_type; |
| 114 | }; |
| 115 | template <class T> |
| 116 | typename mcdata<T>::result_type wrap_mean(mcdata<T> const&); |
| 117 | void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}} |
| 118 | void f() { |
| 119 | add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}} |
| 120 | } |
| 121 | } |
Douglas Gregor | bcd6253 | 2010-11-08 15:20:28 +0000 | [diff] [blame] | 122 | |
| 123 | namespace PR7425 { |
| 124 | template<typename T> |
| 125 | void foo() |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | struct B |
| 130 | { |
| 131 | template<typename T> |
| 132 | B(const T&) |
| 133 | { |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | void bar(const B& b) |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | void bar2(const B& b = foo<int>) |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | void test(int argc, char** argv) |
| 146 | { |
| 147 | bar(foo<int>); |
| 148 | bar2(); |
| 149 | } |
| 150 | } |
Richard Trieu | caff247 | 2011-11-23 22:32:32 +0000 | [diff] [blame] | 151 | |
| 152 | namespace test1 { |
| 153 | void fun(int x) {} |
| 154 | |
| 155 | void parameter_number() { |
| 156 | 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)}} |
| 157 | void (*ptr2)(int, int); |
| 158 | ptr2 = &fun; // expected-error {{assigning to 'void (*)(int, int)' from incompatible type 'void (*)(int)': different number of parameters (2 vs 1)}} |
| 159 | } |
| 160 | |
| 161 | void parameter_mismatch() { |
Richard Trieu | 96ed5b6 | 2011-12-13 23:19:45 +0000 | [diff] [blame] | 162 | 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] | 163 | void (*ptr2)(double); |
| 164 | ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}} |
| 165 | } |
| 166 | |
| 167 | void return_type_test() { |
| 168 | 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')}} |
| 169 | int (*ptr2)(int); |
| 170 | ptr2 = &fun; // expected-error {{assigning to 'int (*)(int)' from incompatible type 'void (*)(int)': different return type ('int' vs 'void')}} |
| 171 | } |
| 172 | |
| 173 | int foo(double x, double y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 174 | int foo(int x, int y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 175 | int foo(double x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'double')}} |
| 176 | double foo(float x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 177 | double foo(int x, float y) {return 0;} // expected-note {{candidate function has different number of parameters (expected 1 but has 2)}} |
| 178 | double foo(float x) {return 0;} // expected-note {{candidate function has type mismatch at 1st parameter (expected 'int' but has 'float')}} |
| 179 | double foo(int x) {return 0;} // expected-note {{candidate function has different return type ('int' expected but has 'double')}} |
| 180 | |
| 181 | int (*ptr)(int) = &foo; // expected-error {{address of overloaded function 'foo' does not match required type 'int (int)'}} |
| 182 | |
| 183 | struct Qualifiers { |
| 184 | void N() {}; |
| 185 | void C() const {}; |
| 186 | void V() volatile {}; |
| 187 | void R() __restrict {}; |
| 188 | void CV() const volatile {}; |
| 189 | void CR() const __restrict {}; |
| 190 | void VR() volatile __restrict {}; |
| 191 | void CVR() const volatile __restrict {}; |
| 192 | }; |
| 193 | |
| 194 | |
| 195 | void QualifierTest() { |
| 196 | void (Qualifiers::*X)(); |
| 197 | X = &Qualifiers::C; // expected-error {{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() const': different qualifiers (none vs const)}} |
| 198 | X = &Qualifiers::V; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() volatile': different qualifiers (none vs volatile)}} |
| 199 | X = &Qualifiers::R; // expected-error{{assigning to 'void (test1::Qualifiers::*)()' from incompatible type 'void (test1::Qualifiers::*)() restrict': different qualifiers (none vs restrict)}} |
| 200 | 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)}} |
| 201 | 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)}} |
| 202 | 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)}} |
| 203 | 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)}} |
| 204 | } |
| 205 | |
| 206 | struct Dummy { |
| 207 | void N() {}; |
| 208 | }; |
| 209 | |
| 210 | 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')}} |
| 211 | } |