Skip to content

Commit f6bc614

Browse files
committed
[clan-format] detect function definitions more conservatively
https://reviews.llvm.org/D105964 updated the detection of function definitions. It had the unfortunate effect to start marking object definitions with attribute-like macros as function definitions. This addresses this issue. Reviewed By: owenpan Differential Revision: https://reviews.llvm.org/D107269
1 parent ac2bc4e commit f6bc614

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
24822482
// return i + 1;
24832483
// }
24842484
if (Next->Next && Next->Next->is(tok::identifier) &&
2485-
!(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi)))
2485+
Line.Last->isNot(tok::semi))
24862486
return true;
24872487
for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
24882488
Tok = Tok->Next) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8224,7 +8224,12 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
82248224
"f(i)\n"
82258225
"{\n"
82268226
" return i + 1;\n"
8227-
"}",
8227+
"}\n"
8228+
"int\n" // Break here.
8229+
"f(i)\n"
8230+
"{\n"
8231+
" return i + 1;\n"
8232+
"};",
82288233
Style);
82298234
verifyFormat("int f(a, b, c);\n" // No break here.
82308235
"int\n" // Break here.
@@ -8233,8 +8238,20 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
82338238
"float c;\n"
82348239
"{\n"
82358240
" return a + b < c;\n"
8236-
"}",
8241+
"}\n"
8242+
"int\n" // Break here.
8243+
"f(a, b, c)\n" // Break here.
8244+
"short a, b;\n"
8245+
"float c;\n"
8246+
"{\n"
8247+
" return a + b < c;\n"
8248+
"};",
82378249
Style);
8250+
// The return breaking style doesn't affect object definitions with
8251+
// attribute-like macros.
8252+
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
8253+
" ABSL_GUARDED_BY(mutex) = {};",
8254+
getGoogleStyleWithColumns(40));
82388255

82398256
Style = getGNUStyle();
82408257

0 commit comments

Comments
 (0)