Skip to content

Commit 8097a5d

Browse files
authored
[clang-format] Fix operator overload inconsistency in BreakAfterAttributes: Always (#74943)
Fixes #74901
1 parent f8f8926 commit 8097a5d

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -583,17 +583,15 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
583583
return true;
584584
}
585585

586-
// If the return type spans multiple lines, wrap before the function name.
587-
if (((Current.is(TT_FunctionDeclarationName) &&
588-
!State.Line->ReturnTypeWrapped &&
589-
// Don't break before a C# function when no break after return type.
590-
(!Style.isCSharp() ||
591-
Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
592-
// Don't always break between a JavaScript `function` and the function
593-
// name.
594-
!Style.isJavaScript()) ||
595-
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
596-
Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
586+
if (Current.is(TT_FunctionDeclarationName) &&
587+
!State.Line->ReturnTypeWrapped &&
588+
// Don't break before a C# function when no break after return type.
589+
(!Style.isCSharp() ||
590+
Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
591+
// Don't always break between a JavaScript `function` and the function
592+
// name.
593+
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
594+
CurrentState.BreakBeforeParameter) {
597595
return true;
598596
}
599597

clang/unittests/Format/FormatTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26479,6 +26479,19 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2647926479
"{\n"
2648026480
"}",
2648126481
CtorDtorCode, Style);
26482+
26483+
verifyFormat("struct Foo {\n"
26484+
" [[maybe_unused]]\n"
26485+
" void operator+();\n"
26486+
"};\n"
26487+
"[[nodiscard]]\n"
26488+
"Foo &operator-(Foo &);",
26489+
Style);
26490+
26491+
Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
26492+
verifyFormat("[[nodiscard]]\n"
26493+
"Foo& operator-(Foo&);",
26494+
Style);
2648226495
}
2648326496

2648426497
TEST_F(FormatTest, InsertNewlineAtEOF) {

0 commit comments

Comments
 (0)