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