clang-format: Make short case labels work with #ifs
Before: switch (a) { #if FOO case 0: return 0; #endif } After: switch (a) { #if FOO case 0: return 0; #endif } This fixed llvm.org/PR21544. llvm-svn: 222642
This commit is contained in:
parent
325e486f9b
commit
79f226e780
|
@ -742,10 +742,13 @@ private:
|
|||
return 0;
|
||||
unsigned NumStmts = 0;
|
||||
unsigned Length = 0;
|
||||
bool InPPDirective = I[0]->InPPDirective;
|
||||
for (; NumStmts < 3; ++NumStmts) {
|
||||
if (I + 1 + NumStmts == E)
|
||||
break;
|
||||
const AnnotatedLine *Line = I[1 + NumStmts];
|
||||
if (Line->InPPDirective != InPPDirective)
|
||||
break;
|
||||
if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
|
||||
break;
|
||||
if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,
|
||||
|
|
|
@ -753,6 +753,12 @@ TEST_F(FormatTest, ShortCaseLabels) {
|
|||
"default: y = 1; break;\n"
|
||||
"}",
|
||||
Style);
|
||||
verifyFormat("switch (a) {\n"
|
||||
"#if FOO\n"
|
||||
"case 0: return 0;\n"
|
||||
"#endif\n"
|
||||
"}",
|
||||
Style);
|
||||
verifyFormat("switch (a) {\n"
|
||||
"case 1: {\n"
|
||||
"}\n"
|
||||
|
|
Loading…
Reference in New Issue