clang-format: Fix incorrect calculation of "length" of /**/ comments.

This could lead to column limit violations.

llvm-svn: 272125
This commit is contained in:
Daniel Jasper 2016-06-08 09:45:08 +00:00
parent 2b4d6eae39
commit acadc8e0d6
2 changed files with 14 additions and 3 deletions

View File

@ -1046,6 +1046,9 @@ void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
LineState &State) {
if (!Current.IsMultiline)
return 0;
// Break before further function parameters on all levels.
for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
State.Stack[i].BreakBeforeParameter = true;
@ -1125,10 +1128,10 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
} else {
return 0;
}
} else if (Current.is(TT_BlockComment) && Current.isTrailingComment()) {
if (!Style.ReflowComments ||
} else if (Current.is(TT_BlockComment)) {
if (!Current.isTrailingComment() || !Style.ReflowComments ||
CommentPragmasRegex.match(Current.TokenText.substr(2)))
return 0;
return addMultilineToken(Current, State);
Token.reset(new BreakableBlockComment(
Current, State.Line->Level, StartColumn, Current.OriginalColumn,
!Current.Previous, State.Line->InPPDirective, Encoding, Style));

View File

@ -7024,6 +7024,14 @@ TEST_F(FormatTest, BlockComments) {
"* aaaaaa aaaaaa\n"
"*/",
getLLVMStyleWithColumns(10)));
EXPECT_EQ("int aaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" /* line 1\n"
" bbbbbbbbbbbb */\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" /* line 1\n"
" bbbbbbbbbbbb */ bbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
getLLVMStyleWithColumns(50)));
FormatStyle NoBinPacking = getLLVMStyle();
NoBinPacking.BinPackParameters = false;