diff options
Diffstat (limited to 'clang/lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 8225a0375b4..fcf45c9286f 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -812,13 +812,14 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, AdditionalIndent); const AnnotatedLine *PreviousLine = nullptr; const AnnotatedLine *NextLine = nullptr; + bool PreviousLineFormatted = false; for (const AnnotatedLine *Line = Joiner.getNextMergedLine(DryRun, IndentTracker); Line; Line = NextLine) { const AnnotatedLine &TheLine = *Line; unsigned Indent = IndentTracker.getIndent(); - bool FixIndentation = - FixBadIndentation && (Indent != TheLine.First->OriginalColumn); + bool FixIndentation = (FixBadIndentation || PreviousLineFormatted) && + Indent != TheLine.First->OriginalColumn; bool ShouldFormat = TheLine.Affected || FixIndentation; // We cannot format this line; if the reason is that the line had a // parsing error, remember that. @@ -845,6 +846,7 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, else Penalty += OptimizingLineFormatter(Indenter, Whitespaces, Style, this) .formatLine(TheLine, Indent, DryRun); + PreviousLineFormatted = true; } else { // If no token in the current line is affected, we still need to format // affected children. @@ -875,6 +877,7 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, Whitespaces->addUntouchableToken(*Tok, TheLine.InPPDirective); } NextLine = Joiner.getNextMergedLine(DryRun, IndentTracker); + PreviousLineFormatted = false; } if (!DryRun) markFinalized(TheLine.First); |