[clang] [clang-format] Correctly annotate l_brace after TypenameMacro (PR #96026)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 04:11:45 PDT 2024


================
@@ -3180,6 +3180,18 @@ TEST_F(TokenAnnotatorTest, FunctionTryBlock) {
   EXPECT_TOKEN(Tokens[36], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, TypenameMacro) {
+  auto Style = getLLVMStyle();
+  Style.TypenameMacros.push_back("STRUCT");
+
+  auto Tokens = annotate("STRUCT(T, B) { int i; };", Style);
+  ASSERT_EQ(Tokens.size(), 13u);
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_TypenameMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_TypeDeclarationParen);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_TypeDeclarationParen);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_Unknown);
----------------
HazardyKnusperkeks wrote:

Is `TT_Unknown` the correct type? I know we can't really say if it's a `TT_StructLBrace` or `TT_ClassLBrace` (or even `TT_UnionLBrace`), but would it harm to just guess one of them?

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


More information about the cfe-commits mailing list