Skip to content

Commit

Permalink
[clang-format] Correctly annotate return type of function pointer (#6…
Browse files Browse the repository at this point in the history
…6893)

Fixes #66857.
  • Loading branch information
owenca committed Sep 26, 2023
1 parent 1a5d3b6 commit 6e608dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3144,8 +3144,12 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line) {
}

// Make sure the name is followed by a pair of parentheses.
if (Name)
return Tok->is(tok::l_paren) && Tok->MatchingParen ? Name : nullptr;
if (Name) {
return Tok->is(tok::l_paren) && Tok->isNot(TT_FunctionTypeLParen) &&
Tok->MatchingParen
? Name
: nullptr;
}

// Skip keywords that may precede the constructor/destructor name.
if (Tok->isOneOf(tok::kw_friend, tok::kw_inline, tok::kw_virtual,
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
"FOO Foo();");
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);

Tokens = annotate("struct Foo {\n"
" Bar (*func)();\n"
"};");
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_FunctionTypeLParen);
}

TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {
Expand Down

0 comments on commit 6e608dc

Please sign in to comment.