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 @@ -836,7 +836,8 @@ ExpectedType ToTypeOrErr = import(From.getAsType()); if (!ToTypeOrErr) return ToTypeOrErr.takeError(); - return TemplateArgument(*ToTypeOrErr); + return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false, + From.getIsDefaulted()); } case TemplateArgument::Integral: { @@ -853,14 +854,15 @@ ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); if (!ToTypeOrErr) return ToTypeOrErr.takeError(); - return TemplateArgument(*ToOrErr, *ToTypeOrErr); + return TemplateArgument(*ToOrErr, *ToTypeOrErr, From.getIsDefaulted()); } case TemplateArgument::NullPtr: { ExpectedType ToTypeOrErr = import(From.getNullPtrType()); if (!ToTypeOrErr) return ToTypeOrErr.takeError(); - return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); + return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true, + From.getIsDefaulted()); } case TemplateArgument::Template: { @@ -868,7 +870,7 @@ if (!ToTemplateOrErr) return ToTemplateOrErr.takeError(); - return TemplateArgument(*ToTemplateOrErr); + return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted()); } case TemplateArgument::TemplateExpansion: { @@ -877,13 +879,13 @@ if (!ToTemplateOrErr) return ToTemplateOrErr.takeError(); - return TemplateArgument( - *ToTemplateOrErr, From.getNumTemplateExpansions()); + return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(), + From.getIsDefaulted()); } case TemplateArgument::Expression: if (ExpectedExpr ToExpr = import(From.getAsExpr())) - return TemplateArgument(*ToExpr); + return TemplateArgument(*ToExpr, From.getIsDefaulted()); else return ToExpr.takeError(); 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 @@ -1158,6 +1158,26 @@ ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U); } +TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) { + Decl *FromTU = getTuDecl(R"( + template struct X {}; + template typename TT = X> struct S {}; + S<> s; + )", + Lang_CXX17); + auto *FromSpec = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("S"))); + ASSERT_TRUE(FromSpec); + auto *ToSpec = Import(FromSpec, Lang_CXX03); + ASSERT_TRUE(ToSpec); + auto const &TList = ToSpec->getTemplateArgs(); + for (auto const &Arg : TList.asArray()) { + ASSERT_TRUE(Arg.getIsDefaulted()); + } +} + TEST_P(ASTImporterOptionSpecificTestBase, ImportOfTemplatedDeclOfClassTemplateDecl) { Decl *FromTU = getTuDecl("template struct S{};", Lang_CXX03);