xref: /minix3/external/bsd/llvm/dist/clang/test/FixIt/fixit-function-call.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2> %t
2*f4a2713aSLionel Sambuc // RUN: FileCheck %s < %t
3*f4a2713aSLionel Sambuc // PR5941
4*f4a2713aSLionel Sambuc // END.
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc /* Test fixits for * and & mismatch in function arguments.
7*f4a2713aSLionel Sambuc  * Since fixits are on the notes, they cannot be applied automatically. */
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc typedef int intTy;
10*f4a2713aSLionel Sambuc typedef int intTy2;
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc void f0(int *a);
13*f4a2713aSLionel Sambuc void f1(double *a);
14*f4a2713aSLionel Sambuc void f1(intTy &a);
15*f4a2713aSLionel Sambuc 
f2(intTy2 * a)16*f4a2713aSLionel Sambuc void f2(intTy2 *a) {
17*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'f1
18*f4a2713aSLionel Sambuc // CHECK: dereference the argument with *
19*f4a2713aSLionel Sambuc // CHECK: void f1(intTy &a);
20*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}*(
21*f4a2713aSLionel Sambuc // CHECK-NEXT: fix-it{{.*}})
22*f4a2713aSLionel Sambuc // CHECK: void f1(double *a);
23*f4a2713aSLionel Sambuc   f1(a + 1);
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc // This call cannot be fixed since without resulting in null pointer dereference.
26*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'f1
27*f4a2713aSLionel Sambuc // CHECK-NOT: dereference the argument with *
28*f4a2713aSLionel Sambuc // CHECK-NOT: fix-it
29*f4a2713aSLionel Sambuc   f1((int *)0);
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
f3(int & a)32*f4a2713aSLionel Sambuc void f3(int &a) {
33*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'f0
34*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}&
35*f4a2713aSLionel Sambuc  f0(a);
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc void m(int *a, const int *b); // match 2
40*f4a2713aSLionel Sambuc void m(double *a, int *b); // no match
41*f4a2713aSLionel Sambuc void m(int *a, double *b); // no match
42*f4a2713aSLionel Sambuc void m(intTy &a, int *b); // match 1
43*f4a2713aSLionel Sambuc 
mcaller(intTy2 a,int b)44*f4a2713aSLionel Sambuc void mcaller(intTy2 a, int b) {
45*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'm
46*f4a2713aSLionel Sambuc // CHECK: take the address of the argument with &
47*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}&
48*f4a2713aSLionel Sambuc // CHECK: take the address of the argument with &
49*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}&
50*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}&
51*f4a2713aSLionel Sambuc   m(a, b);
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc // This call cannot be fixed because (a + 1) is not an l-value.
54*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'm
55*f4a2713aSLionel Sambuc // CHECK-NOT: fix-it
56*f4a2713aSLionel Sambuc   m(a + 1, b);
57*f4a2713aSLionel Sambuc }
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc // Test derived to base conversions.
60*f4a2713aSLionel Sambuc struct A {
61*f4a2713aSLionel Sambuc   int xx;
62*f4a2713aSLionel Sambuc };
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc struct B : public A {
65*f4a2713aSLionel Sambuc   double y;
66*f4a2713aSLionel Sambuc };
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc class C : A {};
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc bool br(A &a);
71*f4a2713aSLionel Sambuc bool bp(A *a);
72*f4a2713aSLionel Sambuc bool dv(B b);
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc void u(int x);
75*f4a2713aSLionel Sambuc void u(const C *x);
76*f4a2713aSLionel Sambuc void u(double x);
77*f4a2713aSLionel Sambuc 
dbcaller(A * ptra,B * ptrb,C & c,B & refb)78*f4a2713aSLionel Sambuc void dbcaller(A *ptra, B *ptrb, C &c, B &refb) {
79*f4a2713aSLionel Sambuc   B b;
80*f4a2713aSLionel Sambuc 
81*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'br
82*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}*
83*f4a2713aSLionel Sambuc   br(ptrb); // good
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'bp
86*f4a2713aSLionel Sambuc // CHECK: fix-it{{.*}}&
87*f4a2713aSLionel Sambuc   bp(b); // good
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'dv
90*f4a2713aSLionel Sambuc // CHECK-NOT: fix-it
91*f4a2713aSLionel Sambuc   dv(ptra); // bad: base to derived
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'dv
94*f4a2713aSLionel Sambuc // CHECK: remove &
95*f4a2713aSLionel Sambuc   dv(&b);
96*f4a2713aSLionel Sambuc 
97*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'bp
98*f4a2713aSLionel Sambuc // CHECK: remove *
99*f4a2713aSLionel Sambuc   bp(*ptra);
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc // CHECK: error: no viable overloaded '='
102*f4a2713aSLionel Sambuc // CHECK: remove &
103*f4a2713aSLionel Sambuc   b = &refb;
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc // TODO: Test that we do not provide a fixit when inheritance is private.
106*f4a2713aSLionel Sambuc // CHECK: error: no matching function for call to 'bp
107*f4a2713aSLionel Sambuc // There should not be a fixit here:
108*f4a2713aSLionel Sambuc // CHECK: fix-it
109*f4a2713aSLionel Sambuc   bp(c);
110*f4a2713aSLionel Sambuc 
111*f4a2713aSLionel Sambuc // CHECK: no matching function for call to 'u'
112*f4a2713aSLionel Sambuc // CHECK: candidate function not viable: no known conversion from 'C' to 'const C *' for 1st argument; take the address of the argument with &
113*f4a2713aSLionel Sambuc // CHECK: candidate function not viable
114*f4a2713aSLionel Sambuc // CHECK: candidate function not viable
115*f4a2713aSLionel Sambuc   u(c);
116*f4a2713aSLionel Sambuc }
117*f4a2713aSLionel Sambuc 
118*f4a2713aSLionel Sambuc // CHECK: errors generated
119