r248145 - clang-format: Fix merging short case labels with comments.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 21 02:50:02 PDT 2015
Author: djasper
Date: Mon Sep 21 04:50:01 2015
New Revision: 248145
URL: http://llvm.org/viewvc/llvm-project?rev=248145&view=rev
Log:
clang-format: Fix merging short case labels with comments.
This fixes llvm.org/PR24877.
Patch by Benjamin Daly, thank you!
Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=248145&r1=248144&r2=248145&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Mon Sep 21 04:50:01 2015
@@ -305,7 +305,8 @@ 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::comment))
+ tok::kw_while, tok::comment) ||
+ Line->Last->is(tok::comment))
return 0;
Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space.
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=248145&r1=248144&r2=248145&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep 21 04:50:01 2015
@@ -756,6 +756,9 @@ TEST_F(FormatTest, ShortCaseLabels) {
"case 7:\n"
" // comment\n"
" return;\n"
+ "case 8:\n"
+ " x = 8; // comment\n"
+ " break;\n"
"default: y = 1; break;\n"
"}",
Style);
More information about the cfe-commits
mailing list