diff options
| author | Daniel Jasper <djasper@google.com> | 2016-06-08 09:45:08 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2016-06-08 09:45:08 +0000 |
| commit | acadc8e0d64e90cded8f63a154ab3111a1d294f9 (patch) | |
| tree | 62458aadb6d0fdc3ef1d298cea33673af93942a6 /clang | |
| parent | 2b4d6eae395103b34fe8c9eaf68017a79b72e88b (diff) | |
| download | bcm5719-llvm-acadc8e0d64e90cded8f63a154ab3111a1d294f9.tar.gz bcm5719-llvm-acadc8e0d64e90cded8f63a154ab3111a1d294f9.zip | |
clang-format: Fix incorrect calculation of "length" of /**/ comments.
This could lead to column limit violations.
llvm-svn: 272125
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 9 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index a0aed0dab47..7f88eea4060 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 7491449b67f..be24066b20c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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; |

