diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h --- a/clang/include/clang/AST/ASTImporter.h +++ b/clang/include/clang/AST/ASTImporter.h @@ -379,6 +379,9 @@ return Import(const_cast(FromD)); } + llvm::Expected + Import(const InheritedConstructor &From); + /// Return the copy of the given declaration in the "to" context if /// it has already been imported from the "from" context. Otherwise return /// nullptr. diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -5877,6 +5877,10 @@ return Node.isVirtualAsWritten(); } +AST_MATCHER(CXXConstructorDecl, isInheritingConstructor) { + return Node.isInheritingConstructor(); +} + /// Matches if the given method or class declaration is final. /// /// Given: diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -477,6 +477,9 @@ Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam); + Expected + ImportInheritedConstructor(const InheritedConstructor &From); + template bool hasSameVisibilityContextAndLinkage(T *Found, T *From); @@ -3477,13 +3480,19 @@ importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier()); if (Err) return std::move(Err); + auto ToInheritedConstructor = InheritedConstructor(); + if (FromConstructor->isInheritingConstructor()) { + Expected ImportedInheritedCtor = + import(FromConstructor->getInheritedConstructor()); + if (!ImportedInheritedCtor) + return ImportedInheritedCtor.takeError(); + ToInheritedConstructor = *ImportedInheritedCtor; + } if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(), D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), - InheritedConstructor(), // FIXME: Properly import inherited - // constructor info - TrailingRequiresClause)) + ToInheritedConstructor, TrailingRequiresClause)) return ToFunction; } else if (CXXDestructorDecl *FromDtor = dyn_cast(D)) { @@ -4217,6 +4226,17 @@ return Error::success(); } +Expected +ASTNodeImporter::ImportInheritedConstructor(const InheritedConstructor &From) { + Error Err = Error::success(); + CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor()); + ConstructorUsingShadowDecl *ToShadow = + importChecked(Err, From.getShadowDecl()); + if (Err) + return std::move(Err); + return InheritedConstructor(ToShadow, ToBaseCtor); +} + ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { // Parameters are created in the translation unit's context, then moved // into the function declaration's context afterward. @@ -4756,9 +4776,23 @@ return ToTargetOrErr.takeError(); UsingShadowDecl *ToShadow; - if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, - Name, *ToIntroducerOrErr, *ToTargetOrErr)) - return ToShadow; + if (auto *FromConstructorUsingShadow = + dyn_cast(D)) { + if (GetImportedOrCreateDecl( + ToShadow, D, Importer.getToContext(), DC, Loc, + cast(*ToIntroducerOrErr), *ToTargetOrErr, + FromConstructorUsingShadow->constructsVirtualBase())) + return ToShadow; + // FIXME import the below members! + // FromConstructorUsingShadow->getNominatedBaseClassShadowDecl(); + // FromConstructorUsingShadow->getConstructedBaseClassShadowDecl(); + // FromConstructorUsingShadow->getNominatedBaseClass(); + // FromConstructorUsingShadow->getConstructedBaseClass(); + } else { + if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, + Name, *ToIntroducerOrErr, *ToTargetOrErr)) + return ToShadow; + } ToShadow->setLexicalDeclContext(LexicalDC); ToShadow->setAccess(D->getAccess()); @@ -8617,6 +8651,11 @@ return ToDOrErr; } +llvm::Expected +ASTImporter::Import(const InheritedConstructor &From) { + return ASTNodeImporter(*this).ImportInheritedConstructor(From); +} + Expected ASTImporter::ImportContext(DeclContext *FromDC) { if (!FromDC) return FromDC; diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -6775,6 +6775,31 @@ ToD->getTemplateSpecializationKind()); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportIsInheritingConstructorBit) { + Decl *FromTU = getTuDecl( + R"( + class a { + public: + a(int); + }; + struct b : a { + using a::a; // Ihnerited ctor. + }; + void c() { + (b(0)); + } + )", + Lang_CXX11); + auto *FromD = FirstDeclMatcher().match( + FromTU, cxxConstructorDecl(isInheritingConstructor())); + ASSERT_TRUE(FromD); + ASSERT_TRUE(FromD->isInheritingConstructor()); + + auto *ToD = Import(FromD, Lang_CXX11); + ASSERT_TRUE(ToD); + EXPECT_TRUE(ToD->isInheritingConstructor()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions);