[clang] [clang][ASTImport] fix issue on anonymous enum import (PR #93923)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 3 06:10:09 PDT 2024


================
@@ -9674,6 +9674,40 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
   EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember());
 }
 
+AST_MATCHER_P(EnumDecl, hasEnumConstName, StringRef, ConstName) {
+  for (EnumConstantDecl *D : Node.enumerators())
+    if (D->getName() == ConstName)
+      return true;
+  return false;
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportAnonymousEnum) {
+  const char *ToCode =
+      R"(
+      struct A {
+        enum { E1, E2} x;
+        enum { E3, E4} y;
+      };
+      )";
+  Decl *ToTu = getToTuDecl(ToCode, Lang_CXX11);
+  auto *ToE = FirstDeclMatcher<EnumDecl>().match(
+      ToTu, enumDecl(hasEnumConstName("E1")));
----------------
balazske wrote:

I would like to have a similar check (and a new import and check) with the other enum. This ensures that the enums are not mixed somehow by the import.

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


More information about the cfe-commits mailing list