[clang] [clang-format] Correctly annotate token-pasted function decl names (PR #142337)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 2 01:33:33 PDT 2025


================
@@ -2257,6 +2257,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) \\\n"
+                    "  auto foo##bar() -> Type {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
+  EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
+
----------------
owenca wrote:

Not really as the last try was reverted and we are doing it afresh here. It would be silly to add:
```
EXPECT_TOKEN(Tokens[11], tok::identifier, TT_Unknown);  // Not TT_FunctionDeclarationName
```
because this was the case before that reverted patch and before this patch (after that patch was reverted).

https://github.com/llvm/llvm-project/pull/142337


More information about the cfe-commits mailing list