summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-10-27 16:31:46 +0000
committerDaniel Jasper <djasper@google.com>2014-10-27 16:31:46 +0000
commit56346193894e1afb3b4705fc9526933e11ed4aec (patch)
treef6f74cbb66ca02702ef513e941a1cd64d36b92cd
parent44ed3d04bfdec42f745c73a9a55f5c94886ac1c6 (diff)
downloadbcm5719-llvm-56346193894e1afb3b4705fc9526933e11ed4aec.tar.gz
bcm5719-llvm-56346193894e1afb3b4705fc9526933e11ed4aec.zip
clang-format: Fix bad merging of lines in nested blocks.
Before: SomeFunction([]() { #define A a return 43; }); After: SomeFunction([]() { #define A a return 43; }); llvm-svn: 220684
-rw-r--r--clang/lib/Format/Format.cpp3
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp12
-rw-r--r--clang/unittests/Format/FormatTest.cpp8
3 files changed, 18 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b9d13ab691e..8960823488f 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1277,6 +1277,9 @@ private:
return true;
}
+ if (Previous.Children[0]->First->MustBreakBefore)
+ return false;
+
// Cannot merge multiple statements into a single line.
if (Previous.Children.size() > 1)
return false;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index a324d2fa472..0cc37b15743 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1362,13 +1362,15 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
ChildSize = LastOfChild.isTrailingComment() ? Style.ColumnLimit
: LastOfChild.TotalLength + 1;
}
- if (Current->MustBreakBefore || Current->Previous->Children.size() > 1 ||
+ const FormatToken *Prev= Current->Previous;
+ if (Current->MustBreakBefore || Prev->Children.size() > 1 ||
+ (Prev->Children.size() == 1 &&
+ Prev->Children[0]->First->MustBreakBefore) ||
Current->IsMultiline)
- Current->TotalLength = Current->Previous->TotalLength + Style.ColumnLimit;
+ Current->TotalLength = Prev->TotalLength + Style.ColumnLimit;
else
- Current->TotalLength = Current->Previous->TotalLength +
- Current->ColumnWidth + ChildSize +
- Current->SpacesRequiredBefore;
+ Current->TotalLength = Prev->TotalLength + Current->ColumnWidth +
+ ChildSize + Current->SpacesRequiredBefore;
if (Current->Type == TT_CtorInitializerColon)
InFunctionDecl = false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5642b0f9e65..f29aff8f0e9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9103,6 +9103,14 @@ TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("SomeFunction([]() { // A cool function...\n"
" return 43;\n"
"});");
+ EXPECT_EQ("SomeFunction([]() {\n"
+ "#define A a\n"
+ " return 43;\n"
+ "});",
+ format("SomeFunction([](){\n"
+ "#define A a\n"
+ "return 43;\n"
+ "});"));
verifyFormat("void f() {\n"
" SomeFunction([](decltype(x), A *a) {});\n"
"}");
OpenPOWER on IntegriCloud