Skip to content

Commit b685e13

Browse files
krasimirggtstellar
authored andcommitted
[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 (cherry picked from commit f6bc614)
1 parent e3ec905 commit b685e13

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
@@ -8216,7 +8216,12 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
82168216
"f(i)\n"
82178217
"{\n"
82188218
" return i + 1;\n"
8219-
"}",
8219+
"}\n"
8220+
"int\n" // Break here.
8221+
"f(i)\n"
8222+
"{\n"
8223+
" return i + 1;\n"
8224+
"};",
82208225
Style);
82218226
verifyFormat("int f(a, b, c);\n" // No break here.
82228227
"int\n" // Break here.
@@ -8225,8 +8230,20 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
82258230
"float c;\n"
82268231
"{\n"
82278232
" return a + b < c;\n"
8228-
"}",
8233+
"}\n"
8234+
"int\n" // Break here.
8235+
"f(a, b, c)\n" // Break here.
8236+
"short a, b;\n"
8237+
"float c;\n"
8238+
"{\n"
8239+
" return a + b < c;\n"
8240+
"};",
82298241
Style);
8242+
// The return breaking style doesn't affect object definitions with
8243+
// attribute-like macros.
8244+
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
8245+
" ABSL_GUARDED_BY(mutex) = {};",
8246+
getGoogleStyleWithColumns(40));
82308247

82318248
Style = getGNUStyle();
82328249

0 commit comments

Comments
 (0)