summaryrefslogtreecommitdiffstats
path: root/lib/Format/BreakableToken.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2017-12-04 08:53:16 +0000
committerManuel Klimek <klimek@google.com>2017-12-04 08:53:16 +0000
commitb779bc4dd11d765a78d47fdc4ada14bd9e775a88 (patch)
tree7fa1b9c58f7629303bc3cc70e8ffe4495fc16a47 /lib/Format/BreakableToken.cpp
parent6a217e4c25e66055338c0c58d33d8a7e793f8b28 (diff)
Fix bug where we wouldn't break columns over the limit.
Before, we would not break: int a = foo(/* trailing */); when the end of /* trailing */ was exactly the column limit; the reason is that block comments can have an unbreakable tail length - in this case 2, for the trailing ");"; we would unconditionally account that when calculating the column state at the end of the token, but not correctly add it into the remaining column length before, as we do for string literals. The fix is to correctly account the trailing unbreakable sequence length into our formatting decisions for block comments. Line comments cannot have a trailing unbreakable sequence, so no change is needed for them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319642 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/BreakableToken.cpp')
-rw-r--r--lib/Format/BreakableToken.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp
index a5fabfe237..4735ab3564 100644
--- a/lib/Format/BreakableToken.cpp
+++ b/lib/Format/BreakableToken.cpp
@@ -316,7 +316,8 @@ BreakableBlockComment::BreakableBlockComment(
unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
encoding::Encoding Encoding, const FormatStyle &Style)
: BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style),
- DelimitersOnNewline(false) {
+ DelimitersOnNewline(false),
+ UnbreakableTailLength(Token.UnbreakableTailLength) {
assert(Tok.is(TT_BlockComment) &&
"block comment section must start with a block comment");
@@ -497,7 +498,8 @@ unsigned BreakableBlockComment::getRangeLength(unsigned LineIndex,
unsigned BreakableBlockComment::getRemainingLength(unsigned LineIndex,
unsigned Offset,
unsigned StartColumn) const {
- return getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn);
+ return UnbreakableTailLength +
+ getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn);
}
unsigned BreakableBlockComment::getContentStartColumn(unsigned LineIndex,