From 2cce7b728b88d846713f8f1e69f9cc58623024c2 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() llvm-svn: 265557 --- clang/lib/Format/UnwrappedLineParser.cpp | 4 +++- clang/unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 29635bf706e9..e36d7efffd26 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 55fd5fba4aa4..2790f9dab0dc 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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);