Skip to content

Commit c0ade86

Browse files
owencasallto
authored andcommitted
[clang-format] Correctly annotate token-pasted function decl names (llvm#142337)
Fix llvm#142178
1 parent 1221215 commit c0ade86

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,6 +3848,8 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
38483848
} else {
38493849
if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0)
38503850
return false;
3851+
while (Next && Next->startsSequence(tok::hashhash, tok::identifier))
3852+
Next = Next->Next->Next;
38513853
for (; Next; Next = Next->Next) {
38523854
if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
38533855
Next = Next->MatchingParen;

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
22572257
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
22582258
EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
22592259

2260+
Tokens = annotate("#define FUNC(foo, bar, baz) \\\n"
2261+
" auto foo##bar##baz() -> Type {}");
2262+
ASSERT_EQ(Tokens.size(), 23u) << Tokens;
2263+
EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
2264+
EXPECT_TOKEN(Tokens[16], tok::l_paren, TT_FunctionDeclarationLParen);
2265+
EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow);
2266+
22602267
Tokens = annotate("int iso_time(time_t);");
22612268
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
22622269
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

0 commit comments

Comments
 (0)