Skip to content

Commit 6e608dc

Browse files
authored
[clang-format] Correctly annotate return type of function pointer (llvm#66893)
Fixes llvm#66857.
1 parent 1a5d3b6 commit 6e608dc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,8 +3144,12 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line) {
31443144
}
31453145

31463146
// Make sure the name is followed by a pair of parentheses.
3147-
if (Name)
3148-
return Tok->is(tok::l_paren) && Tok->MatchingParen ? Name : nullptr;
3147+
if (Name) {
3148+
return Tok->is(tok::l_paren) && Tok->isNot(TT_FunctionTypeLParen) &&
3149+
Tok->MatchingParen
3150+
? Name
3151+
: nullptr;
3152+
}
31493153

31503154
// Skip keywords that may precede the constructor/destructor name.
31513155
if (Tok->isOneOf(tok::kw_friend, tok::kw_inline, tok::kw_virtual,

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
16551655
"FOO Foo();");
16561656
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
16571657
EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);
1658+
1659+
Tokens = annotate("struct Foo {\n"
1660+
" Bar (*func)();\n"
1661+
"};");
1662+
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
1663+
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
1664+
EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_FunctionTypeLParen);
16581665
}
16591666

16601667
TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {

0 commit comments

Comments
 (0)