[clang-format] Fix mismatched break in BlockIndent (#124998)
Near the ColumnLimit a break could be inserted before a right parens with BlockIndent without a break after the matching left parens. Avoid these hanging right parens by disallowing breaks before right parens unless there was a break after the left parens. Fixes #103306 (cherry picked from commit b8734797a3f605c4aaa37fcb5007baa273565460)
This commit is contained in:
parent
8f288eb619
commit
e7ae5532bc
@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow breaking before the right parens with block indentation if there was
|
||||||
|
// a break after the left parens, which is tracked by BreakBeforeClosingParen.
|
||||||
|
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
|
||||||
|
Current.is(tok::r_paren)) {
|
||||||
|
return CurrentState.BreakBeforeClosingParen;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't allow breaking before a closing brace of a block-indented braced list
|
// Don't allow breaking before a closing brace of a block-indented braced list
|
||||||
// initializer if there isn't already a break.
|
// initializer if there isn't already a break.
|
||||||
if (Current.is(tok::r_brace) && Current.MatchingParen &&
|
if (Current.is(tok::r_brace) && Current.MatchingParen &&
|
||||||
|
@ -9614,6 +9614,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
|
|||||||
" auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
|
" auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
|
||||||
" ) {};",
|
" ) {};",
|
||||||
Style);
|
Style);
|
||||||
|
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaa(\n"
|
||||||
|
" &bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
||||||
|
");",
|
||||||
|
Style);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTest, ParenthesesAndOperandAlignment) {
|
TEST_F(FormatTest, ParenthesesAndOperandAlignment) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user