blob: a36fd582db2ee49ca00fca54943b06b6998d7110 [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
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
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);
32 g(g2); // expected-error{{call to 'g' is ambiguous; candidates are:}}
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 McCall864c0412011-04-26 20:42:42 +000060 // FIXME: this error message is terrible
61 return makeAC; // expected-error{{cannot bind to a value of unrelated type}}
Douglas Gregor1a8cf732010-04-14 23:11:21 +000062 }
63
John McCall864c0412011-04-26 20:42:42 +000064 C &makeAC();
65 const C &makeAC() const;
Douglas Gregor1a8cf732010-04-14 23:11:21 +000066
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 McCalle9ee23e2010-04-22 18:44:12 +000074
75// PR6886
76namespace 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 Friedmanfb3bb312010-08-24 05:23:20 +000090
91namespace 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 Gregor78c057e2010-09-12 08:16:09 +0000100
101namespace PR8033 {
Douglas Gregor8e960432010-11-08 03:40:48 +0000102 template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note 2{{candidate function [with T1 = const int, T2 = int]}}
103 template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note 2{{candidate function [with T1 = int, T2 = const int]}}
Douglas Gregor78c057e2010-09-12 08:16:09 +0000104 int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \
Douglas Gregor8e960432010-11-08 03:40:48 +0000105 // expected-error{{address of overloaded function 'f' is ambiguous}}
Douglas Gregor78c057e2010-09-12 08:16:09 +0000106
107}
Douglas Gregorfbb6fad2010-09-29 21:14:36 +0000108
109namespace PR8196 {
110 template <typename T> struct mcdata {
111 typedef int result_type;
112 };
113 template <class T>
114 typename mcdata<T>::result_type wrap_mean(mcdata<T> const&);
115 void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}}
116 void f() {
117 add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}}
118 }
119}
Douglas Gregor3afb9772010-11-08 15:20:28 +0000120
121namespace PR7425 {
122 template<typename T>
123 void foo()
124 {
125 }
126
127 struct B
128 {
129 template<typename T>
130 B(const T&)
131 {
132 }
133 };
134
135 void bar(const B& b)
136 {
137 }
138
139 void bar2(const B& b = foo<int>)
140 {
141 }
142
143 void test(int argc, char** argv)
144 {
145 bar(foo<int>);
146 bar2();
147 }
148}