140 lines · cpp
1// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=1 -x c++ %s 2> %t2// RUN: FileCheck %s < %t3// PR59414// 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 'f118// 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 'f127// CHECK-NOT: dereference the argument with *28// CHECK-NOT: fix-it29 f1((int *)0);30}31 32void f3(int &a) {33// CHECK: error: no matching function for call to 'f034// CHECK: fix-it{{.*}}&35 f0(a);36}37 38 39void m(int *a, const int *b); // match 240void m(double *a, int *b); // no match41void m(int *a, double *b); // no match42void m(intTy &a, int *b); // match 143 44void mcaller(intTy2 a, int b) {45// CHECK: error: no matching function for call to 'm46// 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 'm55// CHECK-NOT: fix-it56 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 68class C : A {};69 70bool br(A &a);71bool bp(A *a);72bool dv(B b);73 74void u(int x);75void u(const C *x);76void u(double x);77 78void dbcaller(A *ptra, B *ptrb, C &c, B &refb) {79 B b;80 81// CHECK: error: no matching function for call to 'br82// CHECK: fix-it{{.*}}*83 br(ptrb); // good84 85// CHECK: error: no matching function for call to 'bp86// CHECK: fix-it{{.*}}&87 bp(b); // good88 89// CHECK: error: no matching function for call to 'dv90// CHECK-NOT: fix-it91 dv(ptra); // bad: base to derived92 93// CHECK: error: no matching function for call to 'dv94// CHECK: remove &95 dv(&b);96 97// CHECK: error: no matching function for call to 'bp98// CHECK: remove *99 bp(*ptra);100 101// CHECK: error: no viable overloaded '='102// CHECK: remove &103 b = &refb;104 105// TODO: Test that we do not provide a fixit when inheritance is private.106// CHECK: error: no matching function for call to 'bp107// There should not be a fixit here:108// CHECK: fix-it109 bp(c);110 111// CHECK: no matching function for call to 'u'112// CHECK: candidate function not viable: no known conversion from 'C' to 'const C *' for 1st argument; take the address of the argument with &113// CHECK: candidate function not viable114// CHECK: candidate function not viable115 u(c);116}117 118void accept_void(void*);119 120void issue58958(const char* a, volatile char * v, const volatile char * cv) {121// CHECK: no matching function for call to 'accept_void'122// CHECK-NOT: take the address of the argument with &123 accept_void(a);124// CHECK: no matching function for call to 'accept_void'125// CHECK-NOT: take the address of the argument with &126 accept_void(v);127// CHECK: no matching function for call to 'accept_void'128// CHECK-NOT: take the address of the argument with &129 accept_void(cv);130 char b;131// CHECK: no matching function for call to 'accept_void'132// CHECK: take the address of the argument with &133 accept_void(b);134// CHECK-NOT: no matching function for call to 'accept_void'135// CHECK-NOT: take the address of the argument with &136 accept_void(&b);137}138 139// CHECK: errors generated140