File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -4078,6 +4078,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
40784078 }
40794079
40804080 bool InFunctionDecl = Line.MightBeFunctionDecl ;
4081+ bool InParameterList = false ;
40814082 for (auto *Current = First->Next ; Current; Current = Current->Next ) {
40824083 const FormatToken *Prev = Current->Previous ;
40834084 if (Current->is (TT_LineComment)) {
@@ -4132,6 +4133,19 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
41324133
41334134 Current->CanBreakBefore =
41344135 Current->MustBreakBefore || canBreakBefore (Line, *Current);
4136+
4137+ if (Current->is (TT_FunctionDeclarationLParen)) {
4138+ InParameterList = true ;
4139+ } else if (Current->is (tok::r_paren)) {
4140+ const auto *LParen = Current->MatchingParen ;
4141+ if (LParen && LParen->is (TT_FunctionDeclarationLParen))
4142+ InParameterList = false ;
4143+ } else if (InParameterList &&
4144+ Current->endsSequence (TT_AttributeMacro,
4145+ TT_PointerOrReference)) {
4146+ Current->CanBreakBefore = false ;
4147+ }
4148+
41354149 unsigned ChildSize = 0 ;
41364150 if (Prev->Children .size () == 1 ) {
41374151 FormatToken &LastOfChild = *Prev->Children [0 ]->Last ;
Original file line number Diff line number Diff line change @@ -12664,6 +12664,12 @@ TEST_F(FormatTest, UnderstandsAttributes) {
1266412664 verifyFormat("__attr1() ::qualified_type f();", CustomAttrs);
1266512665 verifyFormat("__attr1(nodebug) ::qualified_type f();", CustomAttrs);
1266612666
12667+ CustomAttrs.AttributeMacros.push_back("my_attr_name");
12668+ verifyFormat("void MyGoodOldFunction(\n"
12669+ " void *const long_enough = nullptr,\n"
12670+ " void *my_attr_name even_longeeeeeeeeeeeeeeeeer = nullptr);",
12671+ CustomAttrs);
12672+
1266712673 // Check that these are not parsed as function declarations:
1266812674 CustomAttrs.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
1266912675 CustomAttrs.BreakBeforeBraces = FormatStyle::BS_Allman;
You can’t perform that action at this time.
0 commit comments