xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/brackets.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*0a6a1f1dSLionel Sambuc // RUN: cp %s %t
3*0a6a1f1dSLionel Sambuc // RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
4*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
5*0a6a1f1dSLionel Sambuc // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
6*0a6a1f1dSLionel Sambuc 
test1()7*0a6a1f1dSLionel Sambuc void test1() {
8*0a6a1f1dSLionel Sambuc   int a[] = {0,1,1,2,3};
9*0a6a1f1dSLionel Sambuc   int []b = {0,1,4,9,16};
10*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
11*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int []b = {0,1,4,9,16};
12*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}      ~~ ^
13*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}         []
14*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:9}:""
15*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:10-[[@LINE-6]]:10}:"[]"
16*0a6a1f1dSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc   int c = a[0];
18*0a6a1f1dSLionel Sambuc   int d = b[0];  // No undeclared identifer error here.
19*0a6a1f1dSLionel Sambuc 
20*0a6a1f1dSLionel Sambuc   int *e = a;
21*0a6a1f1dSLionel Sambuc   int *f = b;  // No undeclared identifer error here.
22*0a6a1f1dSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc   int[1] g[2];
24*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
25*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int[1] g[2];
26*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}     ~~~     ^
27*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}             [1]
28*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:6-[[@LINE-5]]:9}:""
29*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:14-[[@LINE-6]]:14}:"[1]"
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc 
test2()32*0a6a1f1dSLionel Sambuc void test2() {
33*0a6a1f1dSLionel Sambuc   int [3] (*a) = 0;
34*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
35*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int [3] (*a) = 0;
36*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}      ~~~~    ^
37*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}              [3]
38*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
39*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[3]"
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc #ifndef FIXIT
42*0a6a1f1dSLionel Sambuc   // Make sure a is corrected to be like type y, instead of like type z.
43*0a6a1f1dSLionel Sambuc   int (*b)[3] = a;
44*0a6a1f1dSLionel Sambuc   int (*c[3]) = a;  // expected-error{{}}
45*0a6a1f1dSLionel Sambuc #endif
46*0a6a1f1dSLionel Sambuc }
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc struct A {
49*0a6a1f1dSLionel Sambuc   static int [1][1]x;
50*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
51*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  static int [1][1]x;
52*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}             ~~~~~~ ^
53*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}                    [1][1]
54*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:14-[[@LINE-5]]:20}:""
55*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:21-[[@LINE-6]]:21}:"[1][1]"
56*0a6a1f1dSLionel Sambuc };
57*0a6a1f1dSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc int [1][1]A::x = { {42} };
59*0a6a1f1dSLionel Sambuc // expected-error@-1{{brackets go after the unqualified-id}}
60*0a6a1f1dSLionel Sambuc // CHECK: {{^}}int [1][1]A::x = { {42} };
61*0a6a1f1dSLionel Sambuc // CHECK: {{^}}    ~~~~~~    ^
62*0a6a1f1dSLionel Sambuc // CHECK: {{^}}              [1][1]
63*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:11}:""
64*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[1][1]"
65*0a6a1f1dSLionel Sambuc 
66*0a6a1f1dSLionel Sambuc struct B { static int (*x)[5]; };
67*0a6a1f1dSLionel Sambuc int [5] *B::x = 0;
68*0a6a1f1dSLionel Sambuc // expected-error@-1{{brackets go after the unqualified-id}}
69*0a6a1f1dSLionel Sambuc // CHECK: {{^}}int [5] *B::x = 0;
70*0a6a1f1dSLionel Sambuc // CHECK: {{^}}    ~~~~     ^
71*0a6a1f1dSLionel Sambuc // CHECK: {{^}}        (    )[5]
72*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""
73*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:9-[[@LINE-6]]:9}:"("
74*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:14-[[@LINE-7]]:14}:")[5]"
75*0a6a1f1dSLionel Sambuc 
test3()76*0a6a1f1dSLionel Sambuc void test3() {
77*0a6a1f1dSLionel Sambuc   int [3] *a;
78*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
79*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int [3] *a;
80*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}      ~~~~  ^
81*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}          ( )[3]
82*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
83*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
84*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:13-[[@LINE-7]]:13}:")[3]"
85*0a6a1f1dSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc   int (*b)[3] = a;  // no error
87*0a6a1f1dSLionel Sambuc }
88*0a6a1f1dSLionel Sambuc 
test4()89*0a6a1f1dSLionel Sambuc void test4() {
90*0a6a1f1dSLionel Sambuc   int [2] a;
91*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
92*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int [2] a;
93*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}      ~~~~ ^
94*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}           [2]
95*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
96*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:12-[[@LINE-6]]:12}:"[2]"
97*0a6a1f1dSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc   int [2] &b = a;
99*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
100*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int [2] &b = a;
101*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}      ~~~~  ^
102*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}          ( )[2]
103*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
104*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
105*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:13-[[@LINE-7]]:13}:")[2]"
106*0a6a1f1dSLionel Sambuc 
107*0a6a1f1dSLionel Sambuc }
108*0a6a1f1dSLionel Sambuc 
109*0a6a1f1dSLionel Sambuc namespace test5 {
110*0a6a1f1dSLionel Sambuc #ifndef FIXIT
111*0a6a1f1dSLionel Sambuc int [][][];
112*0a6a1f1dSLionel Sambuc // expected-error@-1{{expected unqualified-id}}
113*0a6a1f1dSLionel Sambuc // CHECK: {{^}}int [][][];
114*0a6a1f1dSLionel Sambuc // CHECK: {{^}}    ^
115*0a6a1f1dSLionel Sambuc 
116*0a6a1f1dSLionel Sambuc struct C {
117*0a6a1f1dSLionel Sambuc   int [];
118*0a6a1f1dSLionel Sambuc   // expected-error@-1{{expected member name or ';' after declaration specifiers}}
119*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int [];
120*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  ~~~ ^
121*0a6a1f1dSLionel Sambuc };
122*0a6a1f1dSLionel Sambuc 
123*0a6a1f1dSLionel Sambuc #endif
124*0a6a1f1dSLionel Sambuc }
125*0a6a1f1dSLionel Sambuc 
126*0a6a1f1dSLionel Sambuc namespace test6 {
127*0a6a1f1dSLionel Sambuc struct A {
128*0a6a1f1dSLionel Sambuc   static int arr[3];
129*0a6a1f1dSLionel Sambuc };
130*0a6a1f1dSLionel Sambuc int [3] ::test6::A::arr = {1,2,3};
131*0a6a1f1dSLionel Sambuc // expected-error@-1{{brackets go after the unqualified-id}}
132*0a6a1f1dSLionel Sambuc // CHECK: {{^}}int [3] ::test6::A::arr = {1,2,3};
133*0a6a1f1dSLionel Sambuc // CHECK: {{^}}    ~~~~               ^
134*0a6a1f1dSLionel Sambuc // CHECK: {{^}}                       [3]
135*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""
136*0a6a1f1dSLionel Sambuc // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:24-[[@LINE-6]]:24}:"[3]"
137*0a6a1f1dSLionel Sambuc 
138*0a6a1f1dSLionel Sambuc }
139*0a6a1f1dSLionel Sambuc 
140*0a6a1f1dSLionel Sambuc namespace test7 {
141*0a6a1f1dSLionel Sambuc class A{};
test()142*0a6a1f1dSLionel Sambuc void test() {
143*0a6a1f1dSLionel Sambuc   int [3] A::*a;
144*0a6a1f1dSLionel Sambuc   // expected-error@-1{{brackets go after the unqualified-id}}
145*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}  int [3] A::*a;
146*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}      ~~~~     ^
147*0a6a1f1dSLionel Sambuc   // CHECK: {{^}}          (    )[3]
148*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
149*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
150*0a6a1f1dSLionel Sambuc   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:16-[[@LINE-7]]:16}:")[3]"
151*0a6a1f1dSLionel Sambuc }
152*0a6a1f1dSLionel Sambuc }
153*0a6a1f1dSLionel Sambuc // CHECK: 14 errors generated.
154