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