fixit-vexing-parse.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // RUN: %clang_cc1 -verify -x c++ %s
  2. // RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s
  3. struct S {
  4. int n;
  5. };
  6. struct T {
  7. T();
  8. T(S, S);
  9. int n;
  10. };
  11. struct U {
  12. ~U();
  13. int n;
  14. };
  15. struct V {
  16. ~V();
  17. };
  18. struct W : V {
  19. };
  20. struct X : U {
  21. };
  22. int F1();
  23. S F2();
  24. namespace N {
  25. void test() {
  26. // CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}"
  27. S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  28. // CHECK: fix-it:"{{.*}}":{39:9-39:10}:";"
  29. // CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}"
  30. S s2, // expected-note {{change this ',' to a ';' to call 'F2'}}
  31. F2(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  32. // CHECK: fix-it:"{{.*}}":{44:9-44:11}:""
  33. // CHECK: fix-it:"{{.*}}":{45:9-45:11}:""
  34. T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}}
  35. t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
  36. // Suggest parentheses only around the first argument.
  37. // CHECK: fix-it:"{{.*}}":{50:10-50:10}:"("
  38. // CHECK: fix-it:"{{.*}}":{50:13-50:13}:")"
  39. T t3(S(), S()); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}}
  40. // Check fixit position for pathological case
  41. // CHECK: fix-it:"{{.*}}":{56:11-56:11}:"("
  42. // CHECK: fix-it:"{{.*}}":{56:20-56:20}:")"
  43. float k[1];
  44. int l(int(k[0])); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}}
  45. // Don't emit warning and fixit because this must be a function declaration due to void return type.
  46. typedef void VO;
  47. VO m(int (*p)[4]);
  48. // Don't emit warning and fixit because direct initializer is not permitted here.
  49. if (int n(int())){} // expected-error {{function type is not allowed here}} expected-error {{condition must have an initializer}}
  50. // CHECK: fix-it:"{{.*}}":{66:8-66:10}:" = {}"
  51. U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  52. // CHECK: fix-it:"{{.*}}":{69:8-69:10}:""
  53. V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
  54. // CHECK: fix-it:"{{.*}}":{72:8-72:10}:""
  55. W w(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
  56. // TODO: Removing the parens here would not initialize U::n.
  57. // Maybe suggest an " = X()" initializer for this case?
  58. // Maybe suggest removing the parens anyway?
  59. X x(); // expected-warning {{function declaration}}
  60. // CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0"
  61. int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  62. // CHECK: fix-it:"{{.*}}":{84:11-84:12}:";"
  63. // CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0"
  64. int n2, // expected-note {{change this ',' to a ';' to call 'F1'}}
  65. F1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  66. // CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0"
  67. double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  68. typedef void *Ptr;
  69. // CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0"
  70. Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  71. #define NULL 0
  72. // CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL"
  73. Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  74. // CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false"
  75. bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  76. // CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'"
  77. char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  78. // CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'"
  79. wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
  80. }
  81. }