aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/BreakableToken.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-01-31 14:31:44 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-01-31 14:31:44 +0000
commitdbbfe192b5c6b2715057b88b19cd4de41c09a006 (patch)
tree42ddb0f864affa608525fa73d4bc5286f078c54d /lib/Format/BreakableToken.cpp
parent53b77ccbdd1c2aa882960223d254150e4b60c942 (diff)
[clang-format] Fix reflow in block comment lines with leading whitespace.
Summary: The reflower was not taking into account the additional leading whitespace in block comment lines. source: ``` { /* * long long long long * long * long long long long */ } ``` format (with column limit 20) before: ``` { /* * long long long * long long long long * long long */ } ``` format after: ``` { /* * long long long * long long long * long long long */ } ``` Reviewers: djasper, klimek Reviewed By: djasper Subscribers: cfe-commits, sammccall, klimek Differential Revision: https://reviews.llvm.org/D29326 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293633 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/BreakableToken.cpp')
-rw-r--r--lib/Format/BreakableToken.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp
index 82e62ac80f..683d6e7249 100644
--- a/lib/Format/BreakableToken.cpp
+++ b/lib/Format/BreakableToken.cpp
@@ -521,10 +521,15 @@ unsigned BreakableBlockComment::getLineLengthAfterSplitBefore(
unsigned PreviousEndColumn,
unsigned ColumnLimit,
Split SplitBefore) const {
- if (SplitBefore.first == StringRef::npos ||
- SplitBefore.first + SplitBefore.second < Content[LineIndex].size()) {
- // A piece of line, not the whole, gets reflown.
- return getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
+ if (SplitBefore.first == StringRef::npos ||
+ // Block comment line contents contain the trailing whitespace after the
+ // decoration, so the need of left trim. Note that this behavior is
+ // consistent with the breaking of block comments where the indentation of
+ // a broken line is uniform across all the lines of the block comment.
+ SplitBefore.first + SplitBefore.second <
+ Content[LineIndex].ltrim().size()) {
+ // A piece of line, not the whole, gets reflown.
+ return getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
} else {
// The whole line gets reflown, need to check if we need to insert a break
// for the postfix or not.