[clang-format] Correctly annotate token-pasted function decl names (#… · llvm/llvm-project@f653271 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -3839,6 +3839,8 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
3839 3839 } else {
3840 3840 if (Current.isNot(TT_StartOfName) |
3841 3841 return false;
3842 +while (Next && Next->startsSequence(tok::hashhash, tok::identifier))
3843 + Next = Next->Next->Next;
3842 3844 for (; Next; Next = Next->Next) {
3843 3845 if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
3844 3846 Next = Next->MatchingParen;
Original file line number Diff line number Diff line change
@@ -2187,6 +2187,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
2187 2187 EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
2188 2188 EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
2189 2189
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 +
2190 2197 Tokens = annotate("int iso_time(time_t);");
2191 2198 ASSERT_EQ(Tokens.size(), 7u) << Tokens;
2192 2199 EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);