From: Daniel Jasper Date: Mon, 21 Sep 2015 09:50:01 +0000 (+0000) Subject: clang-format: Fix merging short case labels with comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=594dc4f13a01847a0a32adaf2364cc55cb7703c4;p=clang clang-format: Fix merging short case labels with comments. This fixes llvm.org/PR24877. Patch by Benjamin Daly, thank you! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248145 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 20298d3394..7e1fc3b1dd 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -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. } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index cda8ce4510..e392cf880c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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);