clang-format: Fix label-in-if statement in macros where it is actually used.
authorDaniel Jasper <djasper@google.com>
Wed, 6 Apr 2016 16:41:39 +0000 (16:41 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 6 Apr 2016 16:41:39 +0000 (16:41 +0000)
Before:
  #define A \
    if (a)  \
    label:  \
    f()

After:
  #define A \
    if (a)  \
    label:  \
      f()

llvm-svn: 265557

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index 29635bf..e36d7ef 100644 (file)
@@ -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() {
index 55fd5fb..2790f9d 100644 (file)
@@ -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);