clang-format: Fixes spaces in case statements.

This fixes llvm.org/PR19482.

Before:
  switch (a) {
    case(B) :
      return;
  }

After:
  switch (a) {
    case (B):
      return;
  }

llvm-svn: 207402
This commit is contained in:
Daniel Jasper 2014-04-28 07:48:36 +00:00
parent a19a2e2da6
commit 031e2409f9
2 changed files with 7 additions and 2 deletions

View File

@ -370,7 +370,8 @@ private:
if (Tok->Previous == NULL)
return false;
// Colons from ?: are handled in parseConditional().
if (Tok->Previous->is(tok::r_paren) && Contexts.size() == 1) {
if (Tok->Previous->is(tok::r_paren) && Contexts.size() == 1 &&
Line.First->isNot(tok::kw_case)) {
Tok->Type = TT_CtorInitializerColon;
} else if (Contexts.back().ColonIsDictLiteral) {
Tok->Type = TT_DictLiteral;
@ -1429,7 +1430,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
(Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
tok::kw_switch, tok::kw_catch) ||
tok::kw_switch, tok::kw_catch, tok::kw_case) ||
Left.IsForEachMacro)) ||
(Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
Left.isOneOf(tok::identifier, tok::kw___attribute) &&

View File

@ -618,6 +618,10 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
" break;\n"
" }\n"
"});");
verifyFormat("switch (a) {\n"
"case (b):\n"
" return;\n"
"}");
}
TEST_F(FormatTest, CaseRanges) {