r182932 - Fix another clang-format crasher related to multi-line comments.

Daniel Jasper djasper at google.com
Thu May 30 08:20:30 PDT 2013


Author: djasper
Date: Thu May 30 10:20:29 2013
New Revision: 182932

URL: http://llvm.org/viewvc/llvm-project?rev=182932&view=rev
Log:
Fix another clang-format crasher related to multi-line comments.

This fixes:
/*
*
* something long going over the column limit.
*/

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

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=182932&r1=182931&r2=182932&view=diff
==============================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu May 30 10:20:29 2013
@@ -241,6 +241,9 @@ BreakableBlockComment::BreakableBlockCom
       Lines[i] = Lines[i].substr(Offset);
       LeadingWhitespace[i] += Offset;
     }
+    // Exclude empty lines from the calculation of the left-most column.
+    if (Lines[i].empty())
+      continue;
     IndentAtLineBreak = std::min<int>(IndentAtLineBreak, StartOfLineColumn[i]);
   }
   DEBUG({

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182932&r1=182931&r2=182932&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 30 10:20:29 2013
@@ -3641,6 +3641,17 @@ TEST_F(FormatTest, BlockComments) {
                    "/* */someCall(parameter);",
                    getLLVMStyleWithColumns(15)));
   EXPECT_EQ("/*\n**\n*/", format("/*\n**\n*/"));
+  // FIXME: Consider whether empty lines can dictated the left-most column.
+  EXPECT_EQ("/*\n"
+            "*\n"
+            " * aaaaaa\n"
+            " * aaaaaa\n"
+            "*/",
+            format("/*\n"
+                   "*\n"
+                   " * aaaaaa aaaaaa\n"
+                   "*/",
+                   getLLVMStyleWithColumns(10)));
 
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackParameters = false;





More information about the cfe-commits mailing list