[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / FixIt / fixit-vexing-parse.cpp
blob973c6961a087923f9bcf4bc4dfba0f58a97e1b58
1 // RUN: %clang_cc1 -verify -x c++ -std=c++98 %s
2 // RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++98 %s 2>&1 | FileCheck %s
4 struct S {
5 int n;
6 };
8 struct T {
9 T();
10 T(S, S);
11 int n;
14 struct U {
15 ~U();
16 int n;
19 struct V {
20 ~V();
23 struct W : V {
26 struct X : U {
29 int F1();
30 S F2();
32 namespace N {
33 void test() {
34 // CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}"
35 S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
37 // CHECK: fix-it:"{{.*}}":{39:9-39:10}:";"
38 // CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}"
39 S s2, // expected-note {{change this ',' to a ';' to call 'F2'}}
40 F2(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
42 // CHECK: fix-it:"{{.*}}":{44:9-44:11}:""
43 // CHECK: fix-it:"{{.*}}":{45:9-45:11}:""
44 T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}}
45 t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
47 // Suggest parentheses only around the first argument.
48 // CHECK: fix-it:"{{.*}}":{50:10-50:10}:"("
49 // CHECK: fix-it:"{{.*}}":{50:13-50:13}:")"
50 T t3(S(), S()); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}}
52 // Check fixit position for pathological case
53 // CHECK: fix-it:"{{.*}}":{56:11-56:11}:"("
54 // CHECK: fix-it:"{{.*}}":{56:20-56:20}:")"
55 float k[1];
56 int l(int(k[0])); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}}
58 // Don't emit warning and fixit because this must be a function declaration due to void return type.
59 typedef void VO;
60 VO m(int (*p)[4]);
62 // Don't emit warning and fixit because direct initializer is not permitted here.
63 if (int n(int())){} // expected-error {{function type is not allowed here}}
65 // CHECK: fix-it:"{{.*}}":{66:8-66:10}:" = {}"
66 U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
68 // CHECK: fix-it:"{{.*}}":{69:8-69:10}:""
69 V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
71 // CHECK: fix-it:"{{.*}}":{72:8-72:10}:""
72 W w(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
74 // TODO: Removing the parens here would not initialize U::n.
75 // Maybe suggest an " = X()" initializer for this case?
76 // Maybe suggest removing the parens anyway?
77 X x(); // expected-warning {{function declaration}}
79 // CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0"
80 int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
82 // CHECK: fix-it:"{{.*}}":{84:11-84:12}:";"
83 // CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0"
84 int n2, // expected-note {{change this ',' to a ';' to call 'F1'}}
85 F1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
87 // CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0"
88 double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
90 typedef void *Ptr;
92 // CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0"
93 Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
95 #define NULL 0
96 // CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL"
97 Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
99 // CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false"
100 bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
102 // CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'"
103 char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
105 // CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'"
106 wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
110 namespace RedundantParens {
111 struct Y {
112 Y();
113 Y(int);
114 ~Y();
116 int n;
118 void test() {
119 // CHECK: add a variable name
120 // CHECK: fix-it:"{{.*}}":{[[@LINE+7]]:4-[[@LINE+7]]:4}:" varname"
121 // CHECK: add enclosing parentheses
122 // CHECK: fix-it:"{{.*}}":{[[@LINE+5]]:3-[[@LINE+5]]:3}:"("
123 // CHECK: fix-it:"{{.*}}":{[[@LINE+4]]:7-[[@LINE+4]]:7}:")"
124 // CHECK: remove parentheses
125 // CHECK: fix-it:"{{.*}}":{[[@LINE+2]]:4-[[@LINE+2]]:5}:" "
126 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:6-[[@LINE+1]]:7}:""
127 Y(n); // expected-warning {{declaration of variable named 'n'}} expected-note 3{{}}