]> granicus.if.org Git - clang/commitdiff
clang-format: Don't auto-break short macros in WebKit style.
authorDaniel Jasper <djasper@google.com>
Fri, 8 Nov 2013 17:33:27 +0000 (17:33 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 Nov 2013 17:33:27 +0000 (17:33 +0000)
This fixes llvm.org/PR17842.

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

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

index f2899345fbd020dcec93ad5ac711b710d7ef3df8..a5fc83e84e40f4cf93d27f6102d980c143364834 100644 (file)
@@ -391,7 +391,8 @@ public:
     if (Indent > Style.ColumnLimit)
       return 0;
 
-    unsigned Limit = Style.ColumnLimit - Indent;
+    unsigned Limit =
+        Style.ColumnLimit == 0 ? UINT_MAX : Style.ColumnLimit - Indent;
     // If we already exceed the column limit, we set 'Limit' to 0. The different
     // tryMerge..() functions can then decide whether to still do merging.
     Limit = TheLine->Last->TotalLength > Limit
@@ -757,6 +758,7 @@ private:
     assert(!B.First->Previous);
     A.Last->Next = B.First;
     B.First->Previous = A.Last;
+    B.First->CanBreakBefore = true;
     unsigned LengthA = A.Last->TotalLength + B.First->SpacesRequiredBefore;
     for (FormatToken *Tok = B.First; Tok; Tok = Tok->Next) {
       Tok->TotalLength += LengthA;
index 7e4131bd686296071ea7924e4c637ca2e1be7476..c0c78713db2a9cb4d6bef674a7dd57330003977d 100644 (file)
@@ -7081,6 +7081,15 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
             "    i++;\n"
             "}",
             format("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) { i++; }", Style));
+
+  // Don't automatically break all macro definitions (llvm.org/PR17842).
+  verifyFormat("#define aNumber 10", Style);
+  // However, generally keep the line breaks that the user authored.
+  EXPECT_EQ("#define aNumber \\\n"
+            "    10",
+            format("#define aNumber \\\n"
+                   " 10",
+                   Style));
 }
 
 TEST_F(FormatTest, FormatsProtocolBufferDefinitions) {