summaryrefslogtreecommitdiffstats
path: root/clang/lib
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 /clang/lib
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
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/Format.cpp3
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp12
2 files changed, 10 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;
OpenPOWER on IntegriCloud