blob: d954267f0eb915a16f0867998c463478ffea5b09 [file] [log] [blame]
Anna Zaksb89fe6b2011-07-19 19:49:12 +00001// RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2> %t || true
2// RUN: FileCheck %s < %t
3// PR5941
4// END.
5
6/* Test fixits for * and & mismatch in function arguments.
7 * Since fixits are on the notes, they cannot be applied automatically. */
8
9typedef int intTy;
10typedef int intTy2;
11
12void f0(int *a);
13void f1(double *a);
14void f1(intTy &a);
15
16void f2(intTy2 *a) {
17// CHECK: error: no matching function for call to 'f1
18// CHECK: dereference the argument with *
19// CHECK: void f1(intTy &a);
20// CHECK: fix-it{{.*}}*(
21// CHECK-NEXT: fix-it{{.*}})
22// CHECK: void f1(double *a);
23 f1(a + 1);
24
25// This call cannot be fixed since without resulting in null pointer dereference.
26// CHECK: error: no matching function for call to 'f1
Anna Zaksffe9edd2011-07-21 00:34:39 +000027// CHECK-NOT: dereference the argument with *
Anna Zaksb89fe6b2011-07-19 19:49:12 +000028// CHECK-NOT: fix-it
29 f1((int *)0);
30}
31
32void f3(int &a) {
33// CHECK: error: no matching function for call to 'f0
34// CHECK: fix-it{{.*}}&
35 f0(a);
36}
37
38
39void m(int *a, const int *b); // match 2
40void m(double *a, int *b); // no match
41void m(int *a, double *b); // no match
42void m(intTy &a, int *b); // match 1
43
44void mcaller(intTy2 a, int b) {
45// CHECK: error: no matching function for call to 'm
46// CHECK: take the address of the argument with &
47// CHECK: fix-it{{.*}}&
48// CHECK: take the address of the argument with &
49// CHECK: fix-it{{.*}}&
50// CHECK: fix-it{{.*}}&
51 m(a, b);
52
53// This call cannot be fixed because (a + 1) is not an l-value.
54// CHECK: error: no matching function for call to 'm
55// CHECK-NOT: fix-it
56 m(a + 1, b);
57}
58
59// Test derived to base conversions.
60struct A {
61 int xx;
62};
63
64struct B : public A {
65 double y;
66};
67
Anna Zaksffe9edd2011-07-21 00:34:39 +000068class C : A {};
69
Anna Zaksb89fe6b2011-07-19 19:49:12 +000070bool br(A &a);
71bool bp(A *a);
72bool dv(B b);
73
Anna Zaksffe9edd2011-07-21 00:34:39 +000074void dbcaller(A *ptra, B *ptrb, C &c) {
Anna Zaksb89fe6b2011-07-19 19:49:12 +000075 B b;
76
77// CHECK: error: no matching function for call to 'br
78// CHECK: fix-it{{.*}}*
79 br(ptrb); // good
Anna Zaksffe9edd2011-07-21 00:34:39 +000080
Anna Zaksb89fe6b2011-07-19 19:49:12 +000081// CHECK: error: no matching function for call to 'bp
82// CHECK: fix-it{{.*}}&
83 bp(b); // good
84
85// CHECK: error: no matching function for call to 'dv
86// CHECK-NOT: fix-it
87 dv(ptra); // bad: base to derived
Anna Zaksffe9edd2011-07-21 00:34:39 +000088
89// CHECK: error: no matching function for call to 'dv
90// CHECK: remove &
91 dv(&b);
92
93// CHECK: error: no matching function for call to 'bp
94// CHECK: remove *
95 bp(*ptra);
96
97// TODO: Test that we do not provide a fixit when inheritance is private.
98// CHECK: error: no matching function for call to 'bp
99// There should not be a fixit here:
100// CHECK: fix-it
101 bp(c);
Anna Zaksb89fe6b2011-07-19 19:49:12 +0000102}
103
104// CHECK: errors generated