llvm-project

Форк
0
/
brackets.cpp 
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

7
void test1() {
8
  int a[] = {0,1,1,2,3};
9
  int []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

17
  int c = a[0];
18
  int d = b[0];  // No undeclared identifier error here.
19

20
  int *e = a;
21
  int *f = b;  // No undeclared identifier error here.
22

23
  int[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

32
void test2() {
33
  int [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.
43
  int (*b)[3] = a;
44
  int (*c[3]) = a;  // expected-error{{}}
45
#endif
46
}
47

48
struct A {
49
  static 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

58
int [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

66
struct B { static int (*x)[5]; };
67
int [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

76
void test3() {
77
  int [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

86
  int (*b)[3] = a;  // no error
87
}
88

89
void test4() {
90
  int [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

98
  int [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

109
namespace test5 {
110
#ifndef FIXIT
111
int [][][];
112
// expected-error@-1{{expected unqualified-id}}
113
// CHECK: {{^}}int [][][];
114
// CHECK: {{^}}    ^
115

116
struct 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

126
namespace test6 {
127
struct A {
128
  static int arr[3];
129
};
130
int [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

140
namespace test7 {
141
class A{};
142
void test() {
143
  int [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

154
namespace test8 {
155
struct A {
156
  static const char f[];
157
};
158
const 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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.