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