Skip to content

Commit f653271

Browse files
owencatstellar
authored andcommitted
[clang-format] Correctly annotate token-pasted function decl names (llvm#142337)
Fix llvm#142178 (cherry picked from commit 7bf5862)
1 parent e0586e2 commit f653271

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
@@ -3839,6 +3839,8 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
38393839
} else {
38403840
if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0)
38413841
return false;
3842+
while (Next && Next->startsSequence(tok::hashhash, tok::identifier))
3843+
Next = Next->Next->Next;
38423844
for (; Next; Next = Next->Next) {
38433845
if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
38443846
Next = Next->MatchingParen;

clang/unittests/Format/TokenAnnotatorTest.cpp

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

2190+
Tokens = annotate("#define FUNC(foo, bar, baz) \\\n"
2191+
" auto foo##bar##baz() -> Type {}");
2192+
ASSERT_EQ(Tokens.size(), 23u) << Tokens;
2193+
EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
2194+
EXPECT_TOKEN(Tokens[16], tok::l_paren, TT_FunctionDeclarationLParen);
2195+
EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow);
2196+
21902197
Tokens = annotate("int iso_time(time_t);");
21912198
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
21922199
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

0 commit comments

Comments
 (0)