diff options
author | Manuel Klimek <klimek@google.com> | 2017-12-04 08:53:16 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2017-12-04 08:53:16 +0000 |
commit | 48c930cb1e3400d2bf8fcdf53d786e19b96bd833 (patch) | |
tree | f379e8d5263137f0d1f44adff916000b7199e15c /clang/lib/Format/BreakableToken.cpp | |
parent | 4520d4f8ad017935d54c68762a0c2b1adc8b282c (diff) | |
download | bcm5719-llvm-48c930cb1e3400d2bf8fcdf53d786e19b96bd833.tar.gz bcm5719-llvm-48c930cb1e3400d2bf8fcdf53d786e19b96bd833.zip |
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.
llvm-svn: 319642
Diffstat (limited to 'clang/lib/Format/BreakableToken.cpp')
-rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index a5fabfe2379..4735ab3564f 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/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, |