Home | History | Annotate | Download | only in FixIt
      1 // 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 
      9 typedef int intTy;
     10 typedef int intTy2;
     11 
     12 void f0(int *a);
     13 void f1(double *a);
     14 void f1(intTy &a);
     15 
     16 void 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
     27 // CHECK-NOT: take the address of the argument with &
     28 // CHECK-NOT: fix-it
     29   f1((int *)0);
     30 }
     31 
     32 void f3(int &a) {
     33 // CHECK: error: no matching function for call to 'f0
     34 // CHECK: fix-it{{.*}}&
     35  f0(a);
     36 }
     37 
     38 
     39 void m(int *a, const int *b); // match 2
     40 void m(double *a, int *b); // no match
     41 void m(int *a, double *b); // no match
     42 void m(intTy &a, int *b); // match 1
     43 
     44 void 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.
     60 struct A {
     61   int xx;
     62 };
     63 
     64 struct B : public A {
     65   double y;
     66 };
     67 
     68 bool br(A &a);
     69 bool bp(A *a);
     70 bool dv(B b);
     71 
     72 void dbcaller(A *ptra, B *ptrb) {
     73   B b;
     74 
     75 // CHECK: error: no matching function for call to 'br
     76 // CHECK: fix-it{{.*}}*
     77   br(ptrb); // good
     78 // CHECK: error: no matching function for call to 'bp
     79 // CHECK: fix-it{{.*}}&
     80   bp(b); // good
     81 
     82 // CHECK: error: no matching function for call to 'dv
     83 // CHECK-NOT: fix-it
     84   dv(ptra); // bad: base to derived
     85 }
     86 
     87 // CHECK: errors generated
     88