diff options
author | Daniel Jasper <djasper@google.com> | 2014-11-21 12:36:25 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-11-21 12:36:25 +0000 |
commit | d081e88e79430c6aa716942beb800a804cd52546 (patch) | |
tree | fecc7a6327450fbfada1a611c0806a2bae821132 | |
parent | 77e1a0ad1fa5c71eef1f0a223cdf73615207121b (diff) | |
download | bcm5719-llvm-d081e88e79430c6aa716942beb800a804cd52546.tar.gz bcm5719-llvm-d081e88e79430c6aa716942beb800a804cd52546.zip |
clang-format: Handle comments in short case labels.
With AllowShortCaseLabelsOnASingleLine set to true:
This gets now left unchanged:
case 1:
// comment
return;
Whereas before it was changed into:
case 1: // comment return;
This fixes llvm.org/PR21630.
llvm-svn: 222529
-rw-r--r-- | clang/lib/Format/Format.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 729ca97aabe..b96c17abbc0 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -750,7 +750,7 @@ private: 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, - tok::kw_while)) + tok::kw_while, tok::comment)) return 0; Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space. } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a6bbe16d863..c58ac0a8f9e 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -745,6 +745,11 @@ TEST_F(FormatTest, ShortCaseLabels) { "case 3:\n" "case 4:\n" "case 5: return;\n" + "case 6: // comment\n" + " return;\n" + "case 7:\n" + " // comment\n" + " return;\n" "default: y = 1; break;\n" "}", Style); |