]> granicus.if.org Git - clang/commitdiff
clang-format: Improve heuristic around avoiding bad line breaks.
authorDaniel Jasper <djasper@google.com>
Tue, 15 Jul 2014 09:00:34 +0000 (09:00 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 15 Jul 2014 09:00:34 +0000 (09:00 +0000)
Now, this can be properly formatted:
  static_cast<A< //
      B> *>(     //
      );

Before, clang-format could end up, not formatting the code at all.

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

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

index 2af16fcd0cf7e3a285f59e4a39053f27aa3ec565..014c30e346ad18861a2a54124f1570e7de2d1431 100644 (file)
@@ -108,7 +108,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
   //   ...
   // As they hide "DoSomething" and are generally bad for readability.
   if (Previous.opensScope() && Previous.isNot(tok::l_brace) &&
-      State.LowestLevelOnLine < State.StartOfLineLevel)
+      State.LowestLevelOnLine < State.StartOfLineLevel &&
+      State.LowestLevelOnLine < Current.NestingLevel)
     return false;
   if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
     return false;
index 81b233c2f549161ff2ff61cc5fb792ef9f856166..2ac017c6f59bf6d9b29d31d4e0ef3741f5423225 100644 (file)
@@ -4467,6 +4467,14 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
       "                      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(\n"
       "        bbbbbbbbbbbbbbbbbbbbbbbb);",
       getLLVMStyleWithColumns(72));
+  EXPECT_EQ("static_cast<A< //\n"
+            "    B> *>(\n"
+            "\n"
+            "    );",
+            format("static_cast<A<//\n"
+                   "    B>*>(\n"
+                   "\n"
+                   "    );"));
 
   FormatStyle AlwaysBreak = getLLVMStyle();
   AlwaysBreak.AlwaysBreakTemplateDeclarations = true;