Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
}

if (NextNonComment->isOneOf(TT_StartOfName, TT_PointerOrReference) ||
Previous.isOneOf(tok::coloncolon, tok::equal, TT_JsTypeColon)) {
Previous.isOneOf(TT_PointerOrReference, tok::coloncolon, tok::equal,
TT_JsTypeColon)) {
return ContinuationIndent;
}
if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4343,7 +4343,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
return Style.PenaltyReturnTypeOnItsOwnLine;
return 200;
}
if (Right.is(TT_PointerOrReference))
if (Left.is(TT_PointerOrReference) || Right.is(TT_PointerOrReference))
return 190;
if (Right.is(TT_LambdaArrow))
return 110;
Expand Down Expand Up @@ -6262,8 +6262,10 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
TT_ClassHeadName, TT_QtProperty, tok::kw_operator)) {
return true;
}
// It is fine to break the line when the * or & should be separate from the
// name according to the PointerAlignment config.
if (Left.is(TT_PointerOrReference))
return false;
return Right.SpacesRequiredBefore;
if (Right.isTrailingComment()) {
// We rely on MustBreakBefore being set correctly here as we should not
// change the "binding" behavior of a comment.
Expand Down
22 changes: 22 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8644,6 +8644,28 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
Style);

Style.ColumnLimit = 70;
verifyFormat(
"void foo(const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName*\n"
" my_super_super_super_super_long_variable_name) {}",
Style);
verifyFormat(
"void foo(const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName*\n"
" const my_super_super_super_super_long_variable_name) {}",
Comment on lines +8653 to +8654
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* and const should stay together on the same line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug report says that they should be on separate lines because they can't fit on the same line. I don't see how to satisfy the requirement. Please post the formatted code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style);

Style.PointerAlignment = FormatStyle::PAS_Middle;
verifyFormat(
"void foo(\n"
" const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName *\n"
" my_super_super_super_super_long_variable_name) {}",
Style);
verifyFormat(
"void foo(\n"
" const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName *\n"
" const my_super_super_super_super_long_variable_name) {}",
Comment on lines +8665 to +8666
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Style);

Style = getLLVMStyleWithColumns(45);
Style.PenaltyReturnTypeOnItsOwnLine = 400;
verifyFormat("template <bool abool, // a comment\n"
Expand Down