1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li
3*67e74705SXin Li struct X {
4*67e74705SXin Li int& f(int) const; // expected-note 2 {{candidate function}}
5*67e74705SXin Li float& f(int); // expected-note 2 {{candidate function}}
6*67e74705SXin Li
test_fX7*67e74705SXin Li void test_f(int x) const {
8*67e74705SXin Li int& i = f(x);
9*67e74705SXin Li }
10*67e74705SXin Li
test_f2X11*67e74705SXin Li void test_f2(int x) {
12*67e74705SXin Li float& f2 = f(x);
13*67e74705SXin Li }
14*67e74705SXin Li
15*67e74705SXin Li int& g(int) const; // expected-note 2 {{candidate function}}
16*67e74705SXin Li float& g(int); // expected-note 2 {{candidate function}}
17*67e74705SXin Li static double& g(double); // expected-note 2 {{candidate function}}
18*67e74705SXin Li
19*67e74705SXin Li void h(int);
20*67e74705SXin Li
test_memberX21*67e74705SXin Li void test_member() {
22*67e74705SXin Li float& f1 = f(0);
23*67e74705SXin Li float& f2 = g(0);
24*67e74705SXin Li double& d1 = g(0.0);
25*67e74705SXin Li }
26*67e74705SXin Li
test_member_constX27*67e74705SXin Li void test_member_const() const {
28*67e74705SXin Li int &i1 = f(0);
29*67e74705SXin Li int &i2 = g(0);
30*67e74705SXin Li double& d1 = g(0.0);
31*67e74705SXin Li }
32*67e74705SXin Li
test_member_staticX33*67e74705SXin Li static void test_member_static() {
34*67e74705SXin Li double& d1 = g(0.0);
35*67e74705SXin Li g(0); // expected-error{{call to 'g' is ambiguous}}
36*67e74705SXin Li }
37*67e74705SXin Li };
38*67e74705SXin Li
test(X x,const X xc,X * xp,const X * xcp,volatile X xv,volatile X * xvp)39*67e74705SXin Li void test(X x, const X xc, X* xp, const X* xcp, volatile X xv, volatile X* xvp) {
40*67e74705SXin Li int& i1 = xc.f(0);
41*67e74705SXin Li int& i2 = xcp->f(0);
42*67e74705SXin Li float& f1 = x.f(0);
43*67e74705SXin Li float& f2 = xp->f(0);
44*67e74705SXin Li xv.f(0); // expected-error{{no matching member function for call to 'f'}}
45*67e74705SXin Li xvp->f(0); // expected-error{{no matching member function for call to 'f'}}
46*67e74705SXin Li
47*67e74705SXin Li int& i3 = xc.g(0);
48*67e74705SXin Li int& i4 = xcp->g(0);
49*67e74705SXin Li float& f3 = x.g(0);
50*67e74705SXin Li float& f4 = xp->g(0);
51*67e74705SXin Li double& d1 = xp->g(0.0);
52*67e74705SXin Li double& d2 = X::g(0.0);
53*67e74705SXin Li X::g(0); // expected-error{{call to 'g' is ambiguous}}
54*67e74705SXin Li
55*67e74705SXin Li X::h(0); // expected-error{{call to non-static member function without an object argument}}
56*67e74705SXin Li }
57*67e74705SXin Li
58*67e74705SXin Li struct X1 {
59*67e74705SXin Li int& member();
60*67e74705SXin Li float& member() const;
61*67e74705SXin Li };
62*67e74705SXin Li
63*67e74705SXin Li struct X2 : X1 { };
64*67e74705SXin Li
test_X2(X2 * x2p,const X2 * cx2p)65*67e74705SXin Li void test_X2(X2 *x2p, const X2 *cx2p) {
66*67e74705SXin Li int &ir = x2p->member();
67*67e74705SXin Li float &fr = cx2p->member();
68*67e74705SXin Li }
69*67e74705SXin Li
70*67e74705SXin Li // Tests the exact text used to note the candidates
71*67e74705SXin Li namespace test1 {
72*67e74705SXin Li class A {
73*67e74705SXin Li 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*67e74705SXin Li void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
75*67e74705SXin Li void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
76*67e74705SXin Li 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*67e74705SXin Li 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}}
78*67e74705SXin Li
79*67e74705SXin Li void bar(double d); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
80*67e74705SXin Li void bar(int i); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
81*67e74705SXin Li
82*67e74705SXin Li void baz(A &d); // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}}
83*67e74705SXin Li void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}}
84*67e74705SXin Li
85*67e74705SXin Li // PR 11857
86*67e74705SXin Li void foo(int n); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
87*67e74705SXin Li void foo(unsigned n = 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
88*67e74705SXin Li void rab(double n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
89*67e74705SXin Li void rab(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
90*67e74705SXin Li 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*67e74705SXin Li void zab(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
92*67e74705SXin Li };
93*67e74705SXin Li
test()94*67e74705SXin Li void test() {
95*67e74705SXin Li A a;
96*67e74705SXin Li a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}}
97*67e74705SXin Li
98*67e74705SXin Li const A b = A();
99*67e74705SXin Li b.bar(0); //expected-error {{no matching member function for call to 'bar'}}
100*67e74705SXin Li
101*67e74705SXin Li a.baz(b); //expected-error {{no matching member function for call to 'baz'}}
102*67e74705SXin Li
103*67e74705SXin Li a.rab(); //expected-error {{no matching member function for call to 'rab'}}
104*67e74705SXin Li a.zab(3, 4, 5); //expected-error {{no matching member function for call to 'zab'}}
105*67e74705SXin Li }
106*67e74705SXin Li }
107*67e74705SXin Li
108*67e74705SXin Li namespace b7398190 {
109*67e74705SXin Li struct S {
110*67e74705SXin Li int f(); // expected-note {{'this' argument has type 'const b7398190::S', but method is not marked const}}
111*67e74705SXin Li void f(int); // expected-note {{requires 1 argument, but 0 were provided}}
112*67e74705SXin Li };
113*67e74705SXin Li const S *p;
114*67e74705SXin Li int k = p->f(); // expected-error {{no matching member function for call to 'f'}}
115*67e74705SXin Li }
116