annotate clang/test/SemaCXX/overload-member-call.cpp @ 150:1d019706d866

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