]> granicus.if.org Git - clang/commitdiff
Do not force linebreaks when MaxEmptyLinesToKeep is 0.
authorManuel Klimek <klimek@google.com>
Tue, 28 Jul 2015 15:50:24 +0000 (15:50 +0000)
committerManuel Klimek <klimek@google.com>
Tue, 28 Jul 2015 15:50:24 +0000 (15:50 +0000)
Previously we would format
 call(

     p);
as
 call(
     p);
with MaxEmptyLinesToKeep == 0.

Now we format it as:
  call(p);

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

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

index 36856eaeea97eca9c6b9d050657b0adf639f0a0a..bd6fde0911397139c54e6dfbdbe6ac069935e445 100644 (file)
@@ -2065,7 +2065,7 @@ static bool isAllmanBrace(const FormatToken &Tok) {
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
                                      const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
-  if (Right.NewlinesBefore > 1)
+  if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
     return true;
 
   if (Style.Language == FormatStyle::LK_JavaScript) {
index 9cb1c31b055ffa7691eb51b0a7a789b09e6f8da7..ce7754dd4489ebba9baa44c83b74ecdae7c48cb6 100644 (file)
@@ -7684,6 +7684,13 @@ TEST_F(FormatTest, BreaksStringLiterals) {
             format("#define A \"some text other\";", AlignLeft));
 }
 
+TEST_F(FormatTest, FullyRemoveEmptyLines) {
+  FormatStyle NoEmptyLines = getLLVMStyleWithColumns(80);
+  NoEmptyLines.MaxEmptyLinesToKeep = 0;
+  EXPECT_EQ("int i = a(b());",
+            format("int i=a(\n\n b(\n\n\n )\n\n);", NoEmptyLines));
+}
+
 TEST_F(FormatTest, BreaksStringLiteralsWithTabs) {
   EXPECT_EQ(
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"