Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 904eed3 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 2 | int f(double); |
| 3 | int f(int); |
| 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. |
Eli Friedman | a91eb54 | 2009-12-22 02:10:53 +0000 | [diff] [blame] | 12 | int (*pfe)(...) = &f; // expected-error{{cannot initialize a variable of type 'int (*)(...)' with an rvalue of type '<overloaded function type>'}} |
Douglas Gregor | 904eed3 | 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 | |
| 16 | void g(int (*fp)(int)); // expected-note{{note: candidate function}} |
| 17 | void g(int (*fp)(float)); |
| 18 | void g(int (*fp)(double)); // expected-note{{note: candidate function}} |
| 19 | |
| 20 | int g1(int); |
| 21 | int g1(char); |
| 22 | |
| 23 | int g2(int); |
| 24 | int g2(double); |
| 25 | |
Douglas Gregor | d173b20 | 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 | 904eed3 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 30 | void g_test() { |
| 31 | g(g1); |
| 32 | g(g2); // expected-error{{call to 'g' is ambiguous; candidates are:}} |
Douglas Gregor | d173b20 | 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 | 60d9231 | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 38 | int h1(char); |
Douglas Gregor | d173b20 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | 60d9231 | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 40 | void ha(int (*fp)(int)); |
| 41 | void hb(int (*fp)(double)); |
Douglas Gregor | d173b20 | 2009-09-14 22:02:01 +0000 | [diff] [blame] | 42 | |
| 43 | void h_test() { |
Douglas Gregor | 60d9231 | 2009-09-14 22:31:20 +0000 | [diff] [blame] | 44 | ha(h1); |
| 45 | hb(h1); |
Douglas Gregor | 904eed3 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 46 | } |
Anders Carlsson | 6e8f550 | 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 | 1a8cf73 | 2010-04-14 23:11:21 +0000 | [diff] [blame] | 57 | |
| 58 | struct C { |
| 59 | C &getC() { |
| 60 | return makeAC; // expected-error{{address of overloaded function 'makeAC' cannot be converted to type 'C'}} |
| 61 | } |
| 62 | |
| 63 | C &makeAC(); |
| 64 | const C &makeAC() const; |
| 65 | |
| 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 McCall | e9ee23e | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 73 | |
| 74 | // PR6886 |
| 75 | namespace 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 Friedman | fb3bb31 | 2010-08-24 05:23:20 +0000 | [diff] [blame] | 89 | |
| 90 | namespace 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 Gregor | 78c057e | 2010-09-12 08:16:09 +0000 | [diff] [blame] | 99 | |
| 100 | namespace PR8033 { |
| 101 | template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note{{candidate function [with T1 = const int, T2 = int]}} |
| 102 | template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note{{candidate function [with T1 = int, T2 = const int]}} |
| 103 | int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \ |
| 104 | // expected-error{{cannot initialize a variable of type}} |
| 105 | |
| 106 | } |
Douglas Gregor | fbb6fad | 2010-09-29 21:14:36 +0000 | [diff] [blame] | 107 | |
| 108 | namespace PR8196 { |
| 109 | template <typename T> struct mcdata { |
| 110 | typedef int result_type; |
| 111 | }; |
| 112 | template <class T> |
| 113 | typename mcdata<T>::result_type wrap_mean(mcdata<T> const&); |
| 114 | void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}} |
| 115 | void f() { |
| 116 | add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}} |
| 117 | } |
| 118 | } |