From ebbe2eca322eb1de3a89d63e019869a56db24183 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 6 Apr 2016 16:41:39 +0000 Subject: [PATCH] clang-format: Fix label-in-if statement in macros where it is actually used. Before: #define A \ if (a) \ label: \ f() After: #define A \ if (a) \ label: \ f() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265557 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 4 +++- unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 29635bf706..e36d7efffd 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1573,8 +1573,10 @@ void UnwrappedLineParser::parseLabel() { addUnwrappedLine(); } Line->Level = OldLineLevel; - if (FormatTok->isNot(tok::l_brace)) + if (FormatTok->isNot(tok::l_brace)) { parseStructuralElement(); + addUnwrappedLine(); + } } void UnwrappedLineParser::parseCaseLabel() { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 55fd5fba4a..2790f9dab0 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -296,6 +296,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) { verifyFormat("if (a)\n if (b) {\n f();\n }\ng();"); FormatStyle AllowsMergedIf = getLLVMStyle(); + AllowsMergedIf.AlignEscapedNewlinesLeft = true; AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true; verifyFormat("if (a)\n" " // comment\n" @@ -307,6 +308,11 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) { " f();\n" "}", AllowsMergedIf); + verifyFormat("#define A \\\n" + " if (a) \\\n" + " label: \\\n" + " f()", + AllowsMergedIf); verifyFormat("if (a)\n" " ;", AllowsMergedIf); -- 2.40.0