balazske created this revision. Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp. Herald added a reviewer: a.sidorin. Herald added a reviewer: shafik. Herald added a project: All. balazske requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125986 Files: clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp Index: clang/unittests/AST/ASTImporterTest.cpp =================================================================== --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -910,6 +910,20 @@ functionDecl(hasDescendant(usingEnumDecl(hasName("bar"))))); } +const internal::VariadicDynCastAllOfMatcher<Decl, UsingPackDecl> usingPackDecl; + +TEST_P(ImportDecl, ImportUsingPackDecl) { + MatchVerifier<Decl> Verifier; + testImport( + "struct A { int operator()() { return 1; } };" + "struct B { int operator()() { return 2; } };" + "template<typename ...T> struct C : T... { using T::operator()...; };" + "C<A, B> declToImport;", + Lang_CXX20, "", Lang_CXX20, Verifier, + varDecl(hasType(templateSpecializationType(hasDeclaration( + classTemplateSpecializationDecl(hasDescendant(usingPackDecl()))))))); +} + /// \brief Matches shadow declarations introduced into a scope by a /// (resolved) using declaration. /// Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -548,6 +548,7 @@ ExpectedDecl VisitUsingDecl(UsingDecl *D); ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); + ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D); ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI); ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D); ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); @@ -4832,6 +4833,36 @@ return ToUsingDir; } +ExpectedDecl ASTNodeImporter::VisitUsingPackDecl(UsingPackDecl *D) { + DeclContext *DC, *LexicalDC; + DeclarationName Name; + SourceLocation Loc; + NamedDecl *ToD = nullptr; + if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) + return std::move(Err); + if (ToD) + return ToD; + + auto ToInstantiatedFromUsingOrErr = + Importer.Import(D->getInstantiatedFromUsingDecl()); + if (!ToInstantiatedFromUsingOrErr) + return ToInstantiatedFromUsingOrErr.takeError(); + SmallVector<NamedDecl *, 4> Expansions(D->expansions().size()); + if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin())) + return std::move(Err); + + UsingPackDecl *ToUsingPack; + if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC, + cast<NamedDecl>(*ToInstantiatedFromUsingOrErr), + Expansions)) + return ToUsingPack; + + ToUsingPack->setLexicalDeclContext(LexicalDC); + LexicalDC->addDeclInternal(ToUsingPack); + + return ToUsingPack; +} + ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( UnresolvedUsingValueDecl *D) { DeclContext *DC, *LexicalDC;
Index: clang/unittests/AST/ASTImporterTest.cpp =================================================================== --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -910,6 +910,20 @@ functionDecl(hasDescendant(usingEnumDecl(hasName("bar"))))); } +const internal::VariadicDynCastAllOfMatcher<Decl, UsingPackDecl> usingPackDecl; + +TEST_P(ImportDecl, ImportUsingPackDecl) { + MatchVerifier<Decl> Verifier; + testImport( + "struct A { int operator()() { return 1; } };" + "struct B { int operator()() { return 2; } };" + "template<typename ...T> struct C : T... { using T::operator()...; };" + "C<A, B> declToImport;", + Lang_CXX20, "", Lang_CXX20, Verifier, + varDecl(hasType(templateSpecializationType(hasDeclaration( + classTemplateSpecializationDecl(hasDescendant(usingPackDecl()))))))); +} + /// \brief Matches shadow declarations introduced into a scope by a /// (resolved) using declaration. /// Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -548,6 +548,7 @@ ExpectedDecl VisitUsingDecl(UsingDecl *D); ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); + ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D); ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI); ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D); ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); @@ -4832,6 +4833,36 @@ return ToUsingDir; } +ExpectedDecl ASTNodeImporter::VisitUsingPackDecl(UsingPackDecl *D) { + DeclContext *DC, *LexicalDC; + DeclarationName Name; + SourceLocation Loc; + NamedDecl *ToD = nullptr; + if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) + return std::move(Err); + if (ToD) + return ToD; + + auto ToInstantiatedFromUsingOrErr = + Importer.Import(D->getInstantiatedFromUsingDecl()); + if (!ToInstantiatedFromUsingOrErr) + return ToInstantiatedFromUsingOrErr.takeError(); + SmallVector<NamedDecl *, 4> Expansions(D->expansions().size()); + if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin())) + return std::move(Err); + + UsingPackDecl *ToUsingPack; + if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC, + cast<NamedDecl>(*ToInstantiatedFromUsingOrErr), + Expansions)) + return ToUsingPack; + + ToUsingPack->setLexicalDeclContext(LexicalDC); + LexicalDC->addDeclInternal(ToUsingPack); + + return ToUsingPack; +} + ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( UnresolvedUsingValueDecl *D) { DeclContext *DC, *LexicalDC;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits