From: Daniel Jasper Date: Wed, 8 Jun 2016 09:45:08 +0000 (+0000) Subject: clang-format: Fix incorrect calculation of "length" of /**/ comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5771074b9b002b435f1ba653d60ae2800e2f6dc;p=clang clang-format: Fix incorrect calculation of "length" of /**/ comments. This could lead to column limit violations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272125 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index a0aed0dab4..7f88eea406 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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)); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7491449b67..be24066b20 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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;