Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -3861,7 +3861,9 @@ ASTImporter::getFieldIndex(D) != ASTImporter::getFieldIndex(FoundField)) continue; - + if (D->isAnonymousStructOrUnion() && FoundField->isAnonymousStructOrUnion()) { + continue; + } if (Importer.IsStructurallyEquivalent(D->getType(), FoundField->getType())) { Importer.MapImported(D, FoundField); Index: clang/unittests/AST/ASTImporterTest.cpp =================================================================== --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -2462,6 +2462,36 @@ functionDecl(hasName("f"), hasDescendant(declRefExpr())))))); } +TEST_P(ASTImporterOptionSpecificTestBase, + ImportAnnonymousUnionInClassTest) { + const char *Code = + R"( + class B{ + + public: + + B(){ + c=1; + } + + void foo1(){} + + private: + union{ + int a; + int b; + }; + union { + int c; + int d; + }; + }; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX11); + EXPECT_TRUE(FromTU); +} + + struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {}; TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {