]> granicus.if.org Git - clang/commitdiff
clang-format: Recognize single-line macro usages inside macros.
authorDaniel Jasper <djasper@google.com>
Fri, 3 Jan 2014 11:50:46 +0000 (11:50 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 3 Jan 2014 11:50:46 +0000 (11:50 +0000)
Before:
  #define LIST(L)                                                     \
    L(FirstElement) L(SecondElement) L(ThirdElement) L(FourthElement) \
        L(FifthElement)

After:
  #define LIST(L)    \
    L(FirstElement)  \
    L(SecondElement) \
    L(ThirdElement)  \
    L(FourthElement) \
    L(FifthElement)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198407 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 90fe3bd786071b58021135eb19bee14c4e75e853..0087e5eabe78f213f7d8aa10e1921c864dea96dd 100644 (file)
@@ -719,7 +719,7 @@ void UnwrappedLineParser::parseStructuralElement() {
         // Recognize function-like macro usages without trailing semicolon.
         if (FormatTok->Tok.is(tok::l_paren)) {
           parseParens();
-          if (FormatTok->HasUnescapedNewline &&
+          if (FormatTok->NewlinesBefore > 0 &&
               tokenCanStartNewLine(FormatTok->Tok)) {
             addUnwrappedLine();
             return;
index 66b54ab9d21d3d2d5e84e7e387a81645aec20429..232a063558105276a1eecc64a6dfaf5a8dee3b2b 100644 (file)
@@ -2198,6 +2198,17 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
                    "  IPC_END_MESSAGE_MAP()\n"
                    "}"));
 
+  // Same inside macros.
+  EXPECT_EQ("#define LIST(L) \\\n"
+            "  L(A)          \\\n"
+            "  L(B)          \\\n"
+            "  L(C)",
+            format("#define LIST(L) \\\n"
+                   "  L(A) \\\n"
+                   "  L(B) \\\n"
+                   "  L(C)",
+                   getGoogleStyle()));
+
   // These must not be recognized as macros.
   EXPECT_EQ("int q() {\n"
             "  f(x);\n"