blob: 6963a75ab3991370a86e6529fd394c0f5f8af4e3 [file] [log] [blame]
Richard Trieuf4b81d02014-06-24 23:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: cp %s %t
3// RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
4// RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
5// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
Richard Trieuf4b81d02014-06-24 23:14:24 +00006
7void test1() {
8 int a[] = {0,1,1,2,3};
9 int []b = {0,1,4,9,16};
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000010 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000011 // CHECK: {{^}} int []b = {0,1,4,9,16};
12 // CHECK: {{^}} ~~ ^
13 // CHECK: {{^}} []
14 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:9}:""
15 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:10-[[@LINE-6]]:10}:"[]"
16
17 int c = a[0];
18 int d = b[0]; // No undeclared identifer error here.
19
20 int *e = a;
21 int *f = b; // No undeclared identifer error here.
22
23 int[1] g[2];
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000024 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000025 // CHECK: {{^}} int[1] g[2];
26 // CHECK: {{^}} ~~~ ^
27 // CHECK: {{^}} [1]
28 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:6-[[@LINE-5]]:9}:""
29 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:14-[[@LINE-6]]:14}:"[1]"
30}
31
32void test2() {
33 int [3] (*a) = 0;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000034 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000035 // CHECK: {{^}} int [3] (*a) = 0;
36 // CHECK: {{^}} ~~~~ ^
37 // CHECK: {{^}} [3]
38 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
39 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[3]"
40
41#ifndef FIXIT
42 // Make sure a is corrected to be like type y, instead of like type z.
43 int (*b)[3] = a;
44 int (*c[3]) = a; // expected-error{{}}
45#endif
46}
47
48struct A {
49 static int [1][1]x;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000050 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000051 // CHECK: {{^}} static int [1][1]x;
52 // CHECK: {{^}} ~~~~~~ ^
53 // CHECK: {{^}} [1][1]
54 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:14-[[@LINE-5]]:20}:""
55 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:21-[[@LINE-6]]:21}:"[1][1]"
56};
57
58int [1][1]A::x = { {42} };
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000059// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000060// CHECK: {{^}}int [1][1]A::x = { {42} };
61// CHECK: {{^}} ~~~~~~ ^
62// CHECK: {{^}} [1][1]
63// CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:11}:""
64// CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[1][1]"
65
66struct B { static int (*x)[5]; };
67int [5] *B::x = 0;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000068// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000069// CHECK: {{^}}int [5] *B::x = 0;
70// CHECK: {{^}} ~~~~ ^
71// CHECK: {{^}} ( )[5]
72// CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""
73// CHECK: fix-it:{{.*}}:{[[@LINE-6]]:9-[[@LINE-6]]:9}:"("
74// CHECK: fix-it:{{.*}}:{[[@LINE-7]]:14-[[@LINE-7]]:14}:")[5]"
75
76void test3() {
77 int [3] *a;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000078 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000079 // CHECK: {{^}} int [3] *a;
80 // CHECK: {{^}} ~~~~ ^
81 // CHECK: {{^}} ( )[3]
82 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
83 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
84 // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:13-[[@LINE-7]]:13}:")[3]"
85
86 int (*b)[3] = a; // no error
87}
88
89void test4() {
90 int [2] a;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000091 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +000092 // CHECK: {{^}} int [2] a;
93 // CHECK: {{^}} ~~~~ ^
94 // CHECK: {{^}} [2]
95 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
96 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:12-[[@LINE-6]]:12}:"[2]"
97
98 int [2] &b = a;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +000099 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +0000100 // CHECK: {{^}} int [2] &b = a;
101 // CHECK: {{^}} ~~~~ ^
102 // CHECK: {{^}} ( )[2]
103 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
104 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
105 // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:13-[[@LINE-7]]:13}:")[2]"
106
107}
108
109namespace test5 {
110#ifndef FIXIT
111int [][][];
112// expected-error@-1{{expected unqualified-id}}
113// CHECK: {{^}}int [][][];
114// CHECK: {{^}} ^
115
116struct C {
117 int [];
118 // expected-error@-1{{expected member name or ';' after declaration specifiers}}
119 // CHECK: {{^}} int [];
120 // CHECK: {{^}} ~~~ ^
121};
122
123#endif
124}
125
126namespace test6 {
127struct A {
128 static int arr[3];
129};
130int [3] ::test6::A::arr = {1,2,3};
Nick Lewyckyb443dfe2015-05-01 20:47:19 +0000131// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +0000132// CHECK: {{^}}int [3] ::test6::A::arr = {1,2,3};
133// CHECK: {{^}} ~~~~ ^
134// CHECK: {{^}} [3]
135// CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""
136// CHECK: fix-it:{{.*}}:{[[@LINE-6]]:24-[[@LINE-6]]:24}:"[3]"
137
138}
139
140namespace test7 {
141class A{};
142void test() {
143 int [3] A::*a;
Nick Lewyckyb443dfe2015-05-01 20:47:19 +0000144 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
Richard Trieuf4b81d02014-06-24 23:14:24 +0000145 // CHECK: {{^}} int [3] A::*a;
146 // CHECK: {{^}} ~~~~ ^
147 // CHECK: {{^}} ( )[3]
148 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
149 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
150 // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:16-[[@LINE-7]]:16}:")[3]"
151}
152}
Nick Lewyckyb443dfe2015-05-01 20:47:19 +0000153
154namespace test8 {
155struct A {
156 static const char f[];
157};
158const char[] A::f = "f";
159// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
160}
161// CHECK: 15 errors generated.