diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 5ee9f760b6a2..417a97c44d59 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -1702,7 +1702,7 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { // Remove all declarations, which may be in wrong order in the // lexical DeclContext and then add them in the proper order. for (auto *D : FromRD->decls()) { - if (isa(D) || isa(D)) { + if (isa(D) || isa(D) || isa(D)) { assert(D && "DC contains a null decl"); Decl *ToD = Importer.GetAlreadyImportedOrNull(D); // Remove only the decls which we successfully imported. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index cfee284e6875..17696a38e94f 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -1421,12 +1421,15 @@ TEST_P(ASTImporterOptionSpecificTestBase, AST_MATCHER_P(RecordDecl, hasFieldOrder, std::vector, Order) { size_t Index = 0; - for (FieldDecl *Field : Node.fields()) { - if (Index == Order.size()) - return false; - if (Field->getName() != Order[Index]) - return false; - ++Index; + for (Decl *D : Node.decls()) { + if (isa(D) || isa(D)) { + auto *ND = cast(D); + if (Index == Order.size()) + return false; + if (ND->getName() != Order[Index]) + return false; + ++Index; + } } return Index == Order.size(); } @@ -1493,6 +1496,31 @@ TEST_P(ASTImporterOptionSpecificTestBase, Verifier.match(To, cxxRecordDecl(hasFieldOrder({"a", "b", "c"})))); } +TEST_P(ASTImporterOptionSpecificTestBase, + CXXRecordDeclFieldAndIndirectFieldOrder) { + Decl *From, *To; + std::tie(From, To) = getImportedDecl( + // First field is "a", then the field for unnamed union, then "b" and "c" + // from it (indirect fields), then "d". + R"s( + struct declToImport { + int a = d; + union { + int b; + int c; + }; + int d; + }; + )s", + Lang_CXX11, "", Lang_CXX11); + + MatchVerifier Verifier; + ASSERT_TRUE(Verifier.match( + From, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"})))); + EXPECT_TRUE(Verifier.match( + To, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"})))); +} + TEST_P(ASTImporterOptionSpecificTestBase, ShouldImportImplicitCXXRecordDecl) { Decl *From, *To; std::tie(From, To) = getImportedDecl(