diff options
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 9 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 5470017303d..4c5f3bee15b 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1677,6 +1677,9 @@ private: bool Explicit, TypeSourceInfo *TInfo, SourceLocation LocStart, SourceLocation Loc, SourceLocation LocEnd) { + ArrayRef<ParmVarDecl *> Params = + TInfo->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(); + // Build the implicit deduction guide template. auto *Guide = FunctionDecl::Create(SemaRef.Context, DC, LocStart, Loc, DeductionGuideName, TInfo->getType(), @@ -1685,8 +1688,10 @@ private: if (Explicit) Guide->setExplicitSpecified(); Guide->setRangeEnd(LocEnd); - Guide->setParams( - TInfo->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams()); + Guide->setParams(Params); + + for (auto *Param : Params) + Param->setDeclContext(Guide); auto *GuideTemplate = FunctionTemplateDecl::Create( SemaRef.Context, DC, Loc, DeductionGuideName, TemplateParams, Guide); diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 3d256aa6705..1205fd1cf3d 100644 --- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -168,3 +168,11 @@ namespace nondeducible { typename ...B> X(float) -> X<A, B...>; // ok } + +namespace default_args_from_ctor { + template <class A> struct S { S(A = 0) {} }; + S s(0); + + template <class A> struct T { template<typename B> T(A = 0, B = 0) {} }; + T t(0, 0); +} |