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 @@ -12640,6 +12640,12 @@ TEST_F(FormatTest, UnderstandsAttributes) {
1264012640 AfterType);
1264112641
1264212642 FormatStyle CustomAttrs = getLLVMStyle();
12643+ CustomAttrs.AttributeMacros.push_back("my_attr_name");
12644+ verifyFormat("void MyGoodOldFunction(\n"
12645+ " void *const long_enough = nullptr,\n"
12646+ " void *my_attr_name even_longeeeeeeeeeeeeeeeeer = nullptr);",
12647+ CustomAttrs);
12648+
1264312649 CustomAttrs.AttributeMacros.push_back("__unused");
1264412650 CustomAttrs.AttributeMacros.push_back("__attr1");
1264512651 CustomAttrs.AttributeMacros.push_back("__attr2");
You can’t perform that action at this time.
0 commit comments