[PATCH] D92106: [ASTImporter] Import the default argument of NonTypeTemplateParmDecl
Raphael Isemann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 27 02:40:37 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG89c1a7a67d69: [ASTImporter] Import the default argument of NonTypeTemplateParmDecl (authored by teemperor).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Changed prior to commit:
https://reviews.llvm.org/D92106?vs=307862&id=307999#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92106/new/
https://reviews.llvm.org/D92106
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
@@ -953,6 +953,27 @@
ASSERT_EQ(ToTemplate, ToExpectedDecl);
}
+TEST_P(ASTImporterOptionSpecificTestBase, NonTypeTemplateParmDeclNoDefaultArg) {
+ Decl *FromTU = getTuDecl("template<int N> struct X {};", Lang_CXX03);
+ auto From = FirstDeclMatcher<NonTypeTemplateParmDecl>().match(
+ FromTU, nonTypeTemplateParmDecl(hasName("N")));
+ NonTypeTemplateParmDecl *To = Import(From, Lang_CXX03);
+ ASSERT_FALSE(To->hasDefaultArgument());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, NonTypeTemplateParmDeclDefaultArg) {
+ Decl *FromTU = getTuDecl("template<int S = 1> struct X {};", Lang_CXX03);
+ auto From = FirstDeclMatcher<NonTypeTemplateParmDecl>().match(
+ FromTU, nonTypeTemplateParmDecl(hasName("S")));
+ NonTypeTemplateParmDecl *To = Import(From, Lang_CXX03);
+ ASSERT_TRUE(To->hasDefaultArgument());
+ Stmt *ToArg = To->getDefaultArgument();
+ ASSERT_TRUE(isa<ConstantExpr>(ToArg));
+ ToArg = *ToArg->child_begin();
+ ASSERT_TRUE(isa<IntegerLiteral>(ToArg));
+ ASSERT_EQ(cast<IntegerLiteral>(ToArg)->getValue().getLimitedValue(), 1U);
+}
+
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
@@ -5227,15 +5227,22 @@
if (Err)
return std::move(Err);
- // FIXME: Import default argument.
-
NonTypeTemplateParmDecl *ToD = nullptr;
- (void)GetImportedOrCreateDecl(
- ToD, D, Importer.getToContext(),
- Importer.getToContext().getTranslationUnitDecl(),
- ToInnerLocStart, ToLocation, D->getDepth(),
- D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType,
- D->isParameterPack(), ToTypeSourceInfo);
+ if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
+ Importer.getToContext().getTranslationUnitDecl(),
+ ToInnerLocStart, ToLocation, D->getDepth(),
+ D->getPosition(),
+ ToDeclName.getAsIdentifierInfo(), ToType,
+ D->isParameterPack(), ToTypeSourceInfo))
+ return ToD;
+
+ if (D->hasDefaultArgument()) {
+ ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument());
+ if (!ToDefaultArgOrErr)
+ return ToDefaultArgOrErr.takeError();
+ ToD->setDefaultArgument(*ToDefaultArgOrErr);
+ }
+
return ToD;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92106.307999.patch
Type: text/x-patch
Size: 2755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201127/d8c7323d/attachment.bin>
More information about the cfe-commits
mailing list