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