From: Richard Smith Date: Thu, 16 Feb 2017 21:29:21 +0000 (+0000) Subject: Properly set up the DeclContext for parameters of implicit deduction guides; X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5778b006b7ccd74dfe123acc5329270b3dace30;p=clang Properly set up the DeclContext for parameters of implicit deduction guides; this is needed for deferred instantiation of default arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295379 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 5470017303..4c5f3bee15 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1677,6 +1677,9 @@ private: bool Explicit, TypeSourceInfo *TInfo, SourceLocation LocStart, SourceLocation Loc, SourceLocation LocEnd) { + ArrayRef Params = + TInfo->getTypeLoc().castAs().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().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/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 3d256aa670..1205fd1cf3 100644 --- a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -168,3 +168,11 @@ namespace nondeducible { typename ...B> X(float) -> X; // ok } + +namespace default_args_from_ctor { + template struct S { S(A = 0) {} }; + S s(0); + + template struct T { template T(A = 0, B = 0) {} }; + T t(0, 0); +}