aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-04-28 07:48:36 +0000
committerDaniel Jasper <djasper@google.com>2014-04-28 07:48:36 +0000
commitc944d2a475e3f13d98ea826784c820082c118764 (patch)
tree0a7110b2672d5fe0e3a85882e97c391efa84735a
parent91417ddc6bc41973236554d329b7f0b42a3fac52 (diff)
downloadclang_35a-c944d2a475e3f13d98ea826784c820082c118764.tar.gz
clang-format: Fixes spaces in case statements.
This fixes llvm.org/PR19482. Before: switch (a) { case(B) : return; } After: switch (a) { case (B): return; } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207402 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/TokenAnnotator.cpp5
-rw-r--r--unittests/Format/FormatTest.cpp4
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index d2b79e544e..54961218a2 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -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) &&
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 7d5ad9ba14..c006c399f3 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -618,6 +618,10 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
" break;\n"
" }\n"
"});");
+ verifyFormat("switch (a) {\n"
+ "case (b):\n"
+ " return;\n"
+ "}");
}
TEST_F(FormatTest, CaseRanges) {