llvm-project
96 строк · 2.0 Кб
1// RUN: %clang_cc1 -fsyntax-only -Wextra-semi-stmt -verify %s
2// RUN: cp %s %t
3// RUN: %clang_cc1 -x c++ -Wextra-semi-stmt -fixit %t
4// RUN: %clang_cc1 -x c++ -Wextra-semi-stmt -Werror %t
5
6#define GOODMACRO(varname) int varname
7#define BETTERMACRO(varname) GOODMACRO(varname);
8#define NULLMACRO(varname)
9
10enum MyEnum {
11E1,
12E2
13};
14
15void test() {
16; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
17;
18
19// This removal of extra semi also consumes all the comments.
20// clang-format off
21;;;
22// clang-format on
23
24// clang-format off
25;NULLMACRO(ZZ);
26// clang-format on
27
28{}; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
29
30{
31; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
32}
33
34if (true) {
35; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
36}
37
38GOODMACRO(v0); // OK
39
40GOODMACRO(v1;) // OK
41
42BETTERMACRO(v2) // OK
43
44BETTERMACRO(v3;) // Extra ';', but within macro expansion, so ignored.
45
46BETTERMACRO(v4); // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
47
48BETTERMACRO(v5;); // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
49
50NULLMACRO(v6) // OK
51
52NULLMACRO(v7); // OK. This could be either GOODMACRO() or BETTERMACRO() situation, so we can't know we can drop it.
53
54if (true)
55; // OK
56
57while (true)
58; // OK
59
60do
61; // OK
62while (true);
63
64for (;;) // OK
65; // OK
66
67MyEnum my_enum;
68switch (my_enum) {
69case E1:
70// stuff
71break;
72case E2:; // OK
73}
74
75for (;;) {
76for (;;) {
77goto contin_outer;
78}
79contin_outer:; // OK
80}
81}
82
83;
84
85namespace NS {};
86
87void foo(int x) {
88switch (x) {
89case 0:
90[[fallthrough]];
91case 1:
92return;
93}
94}
95
96[[]];
97