r207402 - clang-format: Fixes spaces in case statements.
Daniel Jasper
djasper at google.com
Mon Apr 28 00:48:36 PDT 2014
Author: djasper
Date: Mon Apr 28 02:48:36 2014
New Revision: 207402
URL: http://llvm.org/viewvc/llvm-project?rev=207402&view=rev
Log:
clang-format: Fixes spaces in case statements.
This fixes llvm.org/PR19482.
Before:
switch (a) {
case(B) :
return;
}
After:
switch (a) {
case (B):
return;
}
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=207402&r1=207401&r2=207402&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Apr 28 02:48:36 2014
@@ -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::spaceRequiredBetwee
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) &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=207402&r1=207401&r2=207402&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 28 02:48:36 2014
@@ -618,6 +618,10 @@ TEST_F(FormatTest, FormatsSwitchStatemen
" break;\n"
" }\n"
"});");
+ verifyFormat("switch (a) {\n"
+ "case (b):\n"
+ " return;\n"
+ "}");
}
TEST_F(FormatTest, CaseRanges) {
More information about the cfe-commits
mailing list