[clang] d597a46 - [clang][ASTImporter] Add support for import of UsingPackDecl.
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 00:59:08 PDT 2022
Author: Balázs Kéri
Date: 2022-06-01T09:58:08+02:00
New Revision: d597a461e0f5b1d7508983878bc5a38326cffd14
URL: https://github.com/llvm/llvm-project/commit/d597a461e0f5b1d7508983878bc5a38326cffd14
DIFF: https://github.com/llvm/llvm-project/commit/d597a461e0f5b1d7508983878bc5a38326cffd14.diff
LOG: [clang][ASTImporter] Add support for import of UsingPackDecl.
Reviewed By: martong
Differential Revision: https://reviews.llvm.org/D125986
Added:
Modified:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 9c4f60511fb2f..5b35b70f09603 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -548,6 +548,7 @@ namespace clang {
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,35 @@ ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
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;
+
+ addDeclToContexts(D, ToUsingPack);
+
+ return ToUsingPack;
+}
+
ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl(
UnresolvedUsingValueDecl *D) {
DeclContext *DC, *LexicalDC;
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index f1965235c9a6d..4d37ac2ebb2ed 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -910,6 +910,20 @@ TEST_P(ImportDecl, ImportUsingEnumDecl) {
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.
///
@@ -1022,6 +1036,31 @@ TEST_P(ImportExpr, DependentSizedArrayType) {
has(fieldDecl(hasType(dependentSizedArrayType())))))));
}
+TEST_P(ASTImporterOptionSpecificTestBase, ImportUsingPackDecl) {
+ Decl *FromTU = getTuDecl(
+ "struct A { int operator()() { return 1; } };"
+ "struct B { int operator()() { return 2; } };"
+ "template<typename ...T> struct C : T... { using T::operator()...; };"
+ "C<A, B> Var;",
+ Lang_CXX20);
+
+ auto From = FirstDeclMatcher<UsingPackDecl>().match(FromTU, usingPackDecl());
+ ASSERT_TRUE(From);
+ auto To = cast<UsingPackDecl>(Import(From, Lang_CXX20));
+ ASSERT_TRUE(To);
+
+ ArrayRef<NamedDecl *> FromExpansions = From->expansions();
+ ArrayRef<NamedDecl *> ToExpansions = To->expansions();
+ ASSERT_EQ(FromExpansions.size(), ToExpansions.size());
+ for (unsigned int I = 0; I < FromExpansions.size(); ++I) {
+ auto ImportedExpansion = Import(FromExpansions[I], Lang_CXX20);
+ EXPECT_EQ(ImportedExpansion, ToExpansions[I]);
+ }
+
+ auto ImportedDC = cast<Decl>(Import(From->getDeclContext(), Lang_CXX20));
+ EXPECT_EQ(ImportedDC, cast<Decl>(To->getDeclContext()));
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, TemplateTypeParmDeclNoDefaultArg) {
Decl *FromTU = getTuDecl("template<typename T> struct X {};", Lang_CXX03);
auto From = FirstDeclMatcher<TemplateTypeParmDecl>().match(
More information about the cfe-commits
mailing list