blob: e0f34d937f6f1989bee57c91b984058fa8058574 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor88a35142008-12-22 05:46:06 +00002
3struct X {
Sebastian Redl3cb06922009-02-07 19:52:04 +00004 int& f(int) const; // expected-note 2 {{candidate function}}
5 float& f(int); // expected-note 2 {{candidate function}}
Douglas Gregor88a35142008-12-22 05:46:06 +00006
7 void test_f(int x) const {
8 int& i = f(x);
9 }
10
11 void test_f2(int x) {
12 float& f2 = f(x);
13 }
14
Sebastian Redl3cb06922009-02-07 19:52:04 +000015 int& g(int) const; // expected-note 2 {{candidate function}}
16 float& g(int); // expected-note 2 {{candidate function}}
17 static double& g(double); // expected-note 2 {{candidate function}}
Douglas Gregor88a35142008-12-22 05:46:06 +000018
19 void h(int);
Douglas Gregor3f20a682009-01-12 23:20:38 +000020
21 void test_member() {
22 float& f1 = f(0);
23 float& f2 = g(0);
24 double& d1 = g(0.0);
25 }
26
27 void test_member_const() const {
28 int &i1 = f(0);
29 int &i2 = g(0);
30 double& d1 = g(0.0);
31 }
32
33 static void test_member_static() {
34 double& d1 = g(0.0);
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000035 g(0); // expected-error{{call to 'g' is ambiguous}}
Douglas Gregor3f20a682009-01-12 23:20:38 +000036 }
Douglas Gregor88a35142008-12-22 05:46:06 +000037};
38
39void test(X x, const X xc, X* xp, const X* xcp, volatile X xv, volatile X* xvp) {
40 int& i1 = xc.f(0);
41 int& i2 = xcp->f(0);
42 float& f1 = x.f(0);
43 float& f2 = xp->f(0);
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000044 xv.f(0); // expected-error{{no matching member function for call to 'f'}}
45 xvp->f(0); // expected-error{{no matching member function for call to 'f'}}
Douglas Gregor88a35142008-12-22 05:46:06 +000046
47 int& i3 = xc.g(0);
48 int& i4 = xcp->g(0);
49 float& f3 = x.g(0);
50 float& f4 = xp->g(0);
51 double& d1 = xp->g(0.0);
52 double& d2 = X::g(0.0);
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000053 X::g(0); // expected-error{{call to 'g' is ambiguous}}
Douglas Gregor88a35142008-12-22 05:46:06 +000054
55 X::h(0); // expected-error{{call to non-static member function without an object argument}}
56}
Douglas Gregorb1c2ea52009-11-05 00:07:36 +000057
58struct X1 {
59 int& member();
60 float& member() const;
61};
62
63struct X2 : X1 { };
64
65void test_X2(X2 *x2p, const X2 *cx2p) {
66 int &ir = x2p->member();
67 float &fr = cx2p->member();
68}
John McCalladbb8f82010-01-13 09:16:55 +000069
70// Tests the exact text used to note the candidates
71namespace test1 {
72 class A {
Chris Lattner58f9e132010-09-05 00:04:01 +000073 template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'const char [6]' to 'unsigned int' for 2nd argument}}
74 void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
John McCalladbb8f82010-01-13 09:16:55 +000075 void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
76 void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
77 void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
John McCalle81e15e2010-01-14 00:56:20 +000078
Chris Lattner0c42bb62010-09-05 00:17:29 +000079 void bar(double d); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
80 void bar(int i); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
John McCall651f3ee2010-01-14 03:28:57 +000081
Chris Lattner0c42bb62010-09-05 00:17:29 +000082 void baz(A &d); // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}}
83 void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}}
Richard Smithf7b80562012-05-11 05:16:41 +000084
85 // PR 11857
Richard Smithc608c3c2012-05-15 06:21:54 +000086 void foo(int n); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
87 void foo(unsigned n = 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
88 void rab(double n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
89 void rab(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
Richard Smithf7b80562012-05-11 05:16:41 +000090 void zab(double n = 0.0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
91 void zab(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
John McCalladbb8f82010-01-13 09:16:55 +000092 };
93
94 void test() {
95 A a;
96 a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}}
John McCalle81e15e2010-01-14 00:56:20 +000097
Douglas Gregor9db7dbb2010-01-31 09:12:51 +000098 const A b = A();
John McCalle81e15e2010-01-14 00:56:20 +000099 b.bar(0); //expected-error {{no matching member function for call to 'bar'}}
John McCall651f3ee2010-01-14 03:28:57 +0000100
101 a.baz(b); //expected-error {{no matching member function for call to 'baz'}}
Richard Smithf7b80562012-05-11 05:16:41 +0000102
103 a.rab(); //expected-error {{no matching member function for call to 'rab'}}
104 a.zab(3, 4, 5); //expected-error {{no matching member function for call to 'zab'}}
John McCalladbb8f82010-01-13 09:16:55 +0000105 }
106}
107
Richard Smith98bfbf52013-01-26 02:07:32 +0000108namespace b7398190 {
109 struct S {
110 int f(); // expected-note {{'this' argument has type 'const b7398190::S', but method is not marked const}}
111 void f(int); // expected-note {{requires 1 argument, but 0 were provided}}
112 };
113 const S *p;
114 int k = p->f(); // expected-error {{no matching member function for call to 'f'}}
115}