Author: djasper Date: Wed Jun 8 04:45:08 2016 New Revision: 272125 URL: http://llvm.org/viewvc/llvm-project?rev=272125&view=rev Log: clang-format: Fix incorrect calculation of "length" of /**/ comments.
This could lead to column limit violations. Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=272125&r1=272124&r2=272125&view=diff ============================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original) +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Jun 8 04:45:08 2016 @@ -1046,6 +1046,9 @@ void ContinuationIndenter::moveStateToNe 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::breakProt } 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)); Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=272125&r1=272124&r2=272125&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jun 8 04:45:08 2016 @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits