diff options
-rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Format/BreakableToken.h | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 9 |
3 files changed, 17 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, diff --git a/clang/lib/Format/BreakableToken.h b/clang/lib/Format/BreakableToken.h index 8d9b2b295c9..8ef26ef464d 100644 --- a/clang/lib/Format/BreakableToken.h +++ b/clang/lib/Format/BreakableToken.h @@ -405,6 +405,10 @@ private: // If true, make sure that the opening '/**' and the closing '*/' ends on a // line of itself. Styles like jsdoc require this for multiline comments. bool DelimitersOnNewline; + + // Length of the sequence of tokens after this string literal that cannot + // contain line breaks. + unsigned UnbreakableTailLength; }; class BreakableLineCommentSection : public BreakableComment { diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 220ce08ff53..ed11fbdb1fc 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -3080,6 +3080,15 @@ TEST_F(FormatTestComments, PythonStyleComments) { getTextProtoStyleWithColumns(20))); } +TEST_F(FormatTestComments, BreaksBeforeTrailingUnbreakableSequence) { + // The end of /* trail */ is exactly at 80 columns, but the unbreakable + // trailing sequence ); after it exceeds the column limit. Make sure we + // correctly break the line in that case. + verifyFormat("int a =\n" + " foo(/* trail */);", + getLLVMStyleWithColumns(23)); +} + } // end namespace } // end namespace format } // end namespace clang |