llvm-project
161 строка · 5.5 Кб
1// 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 -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
6
7void test1() {
8int a[] = {0,1,1,2,3};
9int []b = {0,1,4,9,16};
10// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
11// 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
17int c = a[0];
18int d = b[0]; // No undeclared identifier error here.
19
20int *e = a;
21int *f = b; // No undeclared identifier error here.
22
23int[1] g[2];
24// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
25// 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() {
33int [3] (*a) = 0;
34// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
35// 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.
43int (*b)[3] = a;
44int (*c[3]) = a; // expected-error{{}}
45#endif
46}
47
48struct A {
49static int [1][1]x;
50// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
51// 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} };
59// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
60// 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;
68// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
69// 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() {
77int [3] *a;
78// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
79// 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
86int (*b)[3] = a; // no error
87}
88
89void test4() {
90int [2] a;
91// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
92// 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
98int [2] &b = a;
99// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
100// 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 {
117int [];
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 {
128static int arr[3];
129};
130int [3] ::test6::A::arr = {1,2,3};
131// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
132// 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() {
143int [3] A::*a;
144// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
145// 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}
153
154namespace test8 {
155struct A {
156static 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.
162