summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/Format.cpp11
-rw-r--r--clang/unittests/Format/FormatTest.cpp15
2 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ce39c480e78..fe6660b3bc3 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -530,10 +530,14 @@ private:
I != E; ++I) {
unsigned Indent =
ParentIndent + ((*I)->Level - Line.Level) * Style.IndentWidth;
- if (!DryRun)
+ if (!DryRun) {
+ unsigned Newlines = std::min((*I)->First->NewlinesBefore,
+ Style.MaxEmptyLinesToKeep + 1);
+ Newlines = std::max(1u, Newlines);
Whitespaces->replaceWhitespace(
- *(*I)->First, /*Newlines=*/1, /*Spaces=*/Indent,
+ *(*I)->First, Newlines, /*Spaces=*/Indent,
/*StartOfTokenColumn=*/Indent, Line.InPPDirective);
+ }
UnwrappedLineFormatter Formatter(Indenter, Whitespaces, Style, **I);
Penalty += Formatter.format(Indent, DryRun);
}
@@ -552,6 +556,9 @@ private:
/*Newlines=*/0, /*Spaces=*/1,
/*StartOfTokenColumn=*/State.Column,
State.Line->InPPDirective);
+ UnwrappedLineFormatter Formatter(Indenter, Whitespaces, Style,
+ *LBrace.Children[0]);
+ Penalty += Formatter.format(State.Column + 1, DryRun);
}
State.Column += 1 + LBrace.Children[0]->Last->TotalLength;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 10a6316054b..ef7d63c1ebb 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2276,6 +2276,19 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
" somethingElse();\n"
"});",
getLLVMStyleWithColumns(29)));
+ EXPECT_EQ("DEBUG({ int i; });", format("DEBUG({ int i; });"));
+ EXPECT_EQ("DEBUG({\n"
+ " int i;\n"
+ "\n"
+ " // comment\n"
+ " int j;\n"
+ "});",
+ format("DEBUG({\n"
+ " int i;\n"
+ "\n"
+ " // comment\n"
+ " int j;\n"
+ "});"));
}
TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
@@ -6395,7 +6408,7 @@ TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("auto c = { [&a, &a, a] {\n"
" [=, a, b, &c] { return b++; }();\n"
"} }\n");
- verifyFormat("auto c = { [&a, &a, a] { [=, a, b, &c] { }(); } }\n");
+ verifyFormat("auto c = { [&a, &a, a] { [=, a, b, &c] {}(); } }\n");
verifyFormat("void f() {\n"
" other(x.begin(), x.end(), [&](int, int) { return 1; });\n"
"}\n");
OpenPOWER on IntegriCloud