Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit a5778b0

Browse files
committed
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
1 parent 08de7bb commit a5778b0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/SemaTemplate.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,9 @@ struct ConvertConstructorToDeductionGuideTransform {
16771677
bool Explicit, TypeSourceInfo *TInfo,
16781678
SourceLocation LocStart, SourceLocation Loc,
16791679
SourceLocation LocEnd) {
1680+
ArrayRef<ParmVarDecl *> Params =
1681+
TInfo->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams();
1682+
16801683
// Build the implicit deduction guide template.
16811684
auto *Guide = FunctionDecl::Create(SemaRef.Context, DC, LocStart, Loc,
16821685
DeductionGuideName, TInfo->getType(),
@@ -1685,8 +1688,10 @@ struct ConvertConstructorToDeductionGuideTransform {
16851688
if (Explicit)
16861689
Guide->setExplicitSpecified();
16871690
Guide->setRangeEnd(LocEnd);
1688-
Guide->setParams(
1689-
TInfo->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
1691+
Guide->setParams(Params);
1692+
1693+
for (auto *Param : Params)
1694+
Param->setDeclContext(Guide);
16901695

16911696
auto *GuideTemplate = FunctionTemplateDecl::Create(
16921697
SemaRef.Context, DC, Loc, DeductionGuideName, TemplateParams, Guide);

test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,11 @@ namespace nondeducible {
168168
typename ...B>
169169
X(float) -> X<A, B...>; // ok
170170
}
171+
172+
namespace default_args_from_ctor {
173+
template <class A> struct S { S(A = 0) {} };
174+
S s(0);
175+
176+
template <class A> struct T { template<typename B> T(A = 0, B = 0) {} };
177+
T t(0, 0);
178+
}

0 commit comments

Comments
 (0)