[PATCH] D92119: [ASTImporter] Import the default argument of TemplateTemplateParmDecl
Raphael Isemann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 06:13:17 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39a5dd164ca8: [ASTImporter] Import the default argument of TemplateTemplateParmDecl (authored by teemperor).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92119/new/
https://reviews.llvm.org/D92119
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
@@ -901,6 +901,39 @@
.isValid());
}
+TEST_P(ASTImporterOptionSpecificTestBase,
+ TemplateTemplateParmDeclNoDefaultArg) {
+ Decl *FromTU = getTuDecl(R"(
+ template<template<typename> typename TT> struct Y {};
+ )",
+ Lang_CXX17);
+ auto From = FirstDeclMatcher<TemplateTemplateParmDecl>().match(
+ FromTU, templateTemplateParmDecl(hasName("TT")));
+ TemplateTemplateParmDecl *To = Import(From, Lang_CXX17);
+ ASSERT_FALSE(To->hasDefaultArgument());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateTemplateParmDeclDefaultArg) {
+ Decl *FromTU = getTuDecl(R"(
+ template<typename T> struct X {};
+ template<template<typename> typename TT = X> struct Y {};
+ )",
+ Lang_CXX17);
+ auto From = FirstDeclMatcher<TemplateTemplateParmDecl>().match(
+ FromTU, templateTemplateParmDecl(hasName("TT")));
+ TemplateTemplateParmDecl *To = Import(From, Lang_CXX17);
+ ASSERT_TRUE(To->hasDefaultArgument());
+ const TemplateArgument &ToDefaultArg = To->getDefaultArgument().getArgument();
+ ASSERT_TRUE(To->isTemplateDecl());
+ TemplateDecl *ToTemplate = ToDefaultArg.getAsTemplate().getAsTemplateDecl();
+
+ // Find the default argument template 'X' in the AST and compare it against
+ // the default argument we got.
+ auto ToExpectedDecl = FirstDeclMatcher<ClassTemplateDecl>().match(
+ To->getTranslationUnitDecl(), classTemplateDecl(hasName("X")));
+ ASSERT_EQ(ToTemplate, ToExpectedDecl);
+}
+
TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
Decl *FromTU = getTuDecl("template<class X> struct S{};", Lang_CXX03);
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -5250,15 +5250,22 @@
if (!TemplateParamsOrErr)
return TemplateParamsOrErr.takeError();
- // FIXME: Import default argument.
-
TemplateTemplateParmDecl *ToD = nullptr;
- (void)GetImportedOrCreateDecl(
- ToD, D, Importer.getToContext(),
- Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
- D->getDepth(), D->getPosition(), D->isParameterPack(),
- (*NameOrErr).getAsIdentifierInfo(),
- *TemplateParamsOrErr);
+ if (GetImportedOrCreateDecl(
+ ToD, D, Importer.getToContext(),
+ Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
+ D->getDepth(), D->getPosition(), D->isParameterPack(),
+ (*NameOrErr).getAsIdentifierInfo(), *TemplateParamsOrErr))
+ return ToD;
+
+ if (D->hasDefaultArgument()) {
+ Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
+ import(D->getDefaultArgument());
+ if (!ToDefaultArgOrErr)
+ return ToDefaultArgOrErr.takeError();
+ ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+ }
+
return ToD;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92119.307851.patch
Type: text/x-patch
Size: 3250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201126/945ad8d9/attachment.bin>
More information about the cfe-commits
mailing list