[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")));
+  const char *Code =
+      R"(
+      struct A {
+        enum { E1, E2} x;
+        enum { E3, E4} y;
+      };
+      )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromE = FirstDeclMatcher<EnumDecl>().match(
+      FromTU, enumDecl(hasEnumConstName("E1")));
+  auto *ImportedE = Import(FromE, Lang_CXX11);
+  ASSERT_TRUE(ImportedE);
+  EXPECT_EQ(ImportedE, ToE);
+  EXPECT_FALSE(ImportedE->enumerators().empty());
----------------
balazske wrote:

```suggestion
```
This check is not necessary (if the other is here).

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


More information about the cfe-commits mailing list