fixit-function-call.cpp 2.8 KB

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