From 9e32199861c082d36b0439756f616ee91855dd6e Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Tue, 28 Jul 2015 15:50:24 +0000 Subject: [PATCH] Do not force linebreaks when MaxEmptyLinesToKeep is 0. Previously we would format call( p); as call( p); with MaxEmptyLinesToKeep == 0. Now we format it as: call(p); llvm-svn: 243429 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 36856ea..bd6fde0 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 9cb1c31..ce7754d 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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" -- 2.7.4