Skip to content

Commit 7e602ae

Browse files
author
huqizhi
committed
[clang][ASTImport] fix issue on anonymous enum import
1 parent 461cc86 commit 7e602ae

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2929,7 +2929,7 @@ ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
29292929

29302930
// We may already have an enum of the same name; try to find and match it.
29312931
EnumDecl *PrevDecl = nullptr;
2932-
if (!DC->isFunctionOrMethod() && SearchName) {
2932+
if (!DC->isFunctionOrMethod()) {
29332933
SmallVector<NamedDecl *, 4> ConflictingDecls;
29342934
auto FoundDecls =
29352935
Importer.findDeclsInToCtx(DC, SearchName);

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9674,6 +9674,27 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
96749674
EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember());
96759675
}
96769676

9677+
TEST_P(ASTImporterOptionSpecificTestBase, ImportAnonymousEnum) {
9678+
const char *ToCode =
9679+
R"(
9680+
struct A {
9681+
enum { E1,E2} x;
9682+
};
9683+
)";
9684+
(void)getToTuDecl(ToCode, Lang_CXX11);
9685+
const char *Code =
9686+
R"(
9687+
struct A {
9688+
enum { E1,E2} x;
9689+
};
9690+
)";
9691+
Decl *FromTU = getTuDecl(Code, Lang_CXX11);
9692+
auto *FromE = FirstDeclMatcher<EnumDecl>().match(FromTU, enumDecl());
9693+
auto *ToE = Import(FromE, Lang_CXX11);
9694+
ASSERT_TRUE(ToE);
9695+
EXPECT_FALSE(ToE->enumerators().empty());
9696+
}
9697+
96779698
INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
96789699
DefaultTestValuesForRunOptions);
96799700

0 commit comments

Comments
 (0)