[clang-format] Correctly annotate token-pasted function decl names (#142337)
Fix #142178 (cherry picked from commit 7bf5862dbfda590282f50b14e6d7d5f990bf1900)
This commit is contained in:
parent
e0586e278f
commit
f6532710ac
@ -3839,6 +3839,8 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
|
||||
} else {
|
||||
if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0)
|
||||
return false;
|
||||
while (Next && Next->startsSequence(tok::hashhash, tok::identifier))
|
||||
Next = Next->Next->Next;
|
||||
for (; Next; Next = Next->Next) {
|
||||
if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
|
||||
Next = Next->MatchingParen;
|
||||
|
||||
@ -2187,6 +2187,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
|
||||
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
|
||||
EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
|
||||
|
||||
Tokens = annotate("#define FUNC(foo, bar, baz) \\\n"
|
||||
" auto foo##bar##baz() -> Type {}");
|
||||
ASSERT_EQ(Tokens.size(), 23u) << Tokens;
|
||||
EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
|
||||
EXPECT_TOKEN(Tokens[16], tok::l_paren, TT_FunctionDeclarationLParen);
|
||||
EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow);
|
||||
|
||||
Tokens = annotate("int iso_time(time_t);");
|
||||
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
|
||||
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user