addr-of-overloaded-function.cpp revision 78c057e5a16b3ba186cc6453ca26b15745f2b79d
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2int f(double); 3int f(int); 4 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. 12int (*pfe)(...) = &f; // expected-error{{cannot initialize a variable of type 'int (*)(...)' with an rvalue of type '<overloaded function type>'}} 13int (&rfi)(int) = f; // selects f(int) 14int (&rfd)(double) = f; // selects f(double) 15 16void g(int (*fp)(int)); // expected-note{{note: candidate function}} 17void g(int (*fp)(float)); 18void g(int (*fp)(double)); // expected-note{{note: candidate function}} 19 20int g1(int); 21int g1(char); 22 23int g2(int); 24int g2(double); 25 26template<typename T> T g3(T); 27int g3(int); 28int g3(char); 29 30void g_test() { 31 g(g1); 32 g(g2); // expected-error{{call to 'g' is ambiguous; candidates are:}} 33 g(g3); 34} 35 36template<typename T> T h1(T); 37template<typename R, typename A1> R h1(A1); 38int h1(char); 39 40void ha(int (*fp)(int)); 41void hb(int (*fp)(double)); 42 43void h_test() { 44 ha(h1); 45 hb(h1); 46} 47 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}; 57 58struct 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}; 73 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} 89 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} 99 100namespace 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} 107