Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2547,6 +2547,10 @@ TT_DesignatedInitializerLSquare, TT_AttributeSquare)) return 500; } + // Favour breaking between ( and [ when attributes are used as the first + // parameter e.g. foo([[maybe_unused]] T &bar). + if (Left.is(tok::l_paren) && Right.is(TT_AttributeSquare)) + return 1; if (Left.is(tok::coloncolon) || (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) @@ -2635,7 +2639,6 @@ if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous && Left.Previous->isOneOf(tok::identifier, tok::greater)) return 500; - if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) return 100; Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -7661,6 +7661,19 @@ MultiLineFunctions); } +TEST_F(FormatTest, AttributePenaltyBreaking) { + FormatStyle Style = getLLVMStyle(); + verifyFormat("void ABCDEFGH::ABCDEFGHIJKLMN(\n" + " [[maybe_unused]] const shared_ptr &C d) {}", + Style); + verifyFormat("void ABCDEFGH::ABCDEFGHIJK(\n" + " [[maybe_unused]] const shared_ptr &C d) {}", + Style); + verifyFormat("void ABCDEFGH::ABCDEFGH([[maybe_unused]] const " + "shared_ptr &C d) {\n}", + Style); +} + TEST_F(FormatTest, UnderstandsEllipsis) { verifyFormat("int printf(const char *fmt, ...);"); verifyFormat("template void Foo(Ts... ts) { Foo(ts...); }");