r265557 - clang-format: Fix label-in-if statement in macros where it is actually used.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 6 09:41:40 PDT 2016


Author: djasper
Date: Wed Apr  6 11:41:39 2016
New Revision: 265557

URL: http://llvm.org/viewvc/llvm-project?rev=265557&view=rev
Log:
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()

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=265557&r1=265556&r2=265557&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Apr  6 11:41:39 2016
@@ -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() {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=265557&r1=265556&r2=265557&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr  6 11:41:39 2016
@@ -296,6 +296,7 @@ TEST_F(FormatTest, FormatIfWithoutCompou
   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, FormatIfWithoutCompou
                "    f();\n"
                "}",
                AllowsMergedIf);
+  verifyFormat("#define A \\\n"
+               "  if (a)  \\\n"
+               "  label:  \\\n"
+               "    f()",
+               AllowsMergedIf);
   verifyFormat("if (a)\n"
                "  ;",
                AllowsMergedIf);




More information about the cfe-commits mailing list