summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-02-16 21:29:21 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-02-16 21:29:21 +0000
commitefa919ab074835d1a94fcf2b1a6d1cac03afe20a (patch)
treecdb7d7662d9fb7f302f4d712c902ed377303acee
parent493fb266ed8eb3e2de4c9d5013c9870d555948dc (diff)
downloadbcm5719-llvm-efa919ab074835d1a94fcf2b1a6d1cac03afe20a.tar.gz
bcm5719-llvm-efa919ab074835d1a94fcf2b1a6d1cac03afe20a.zip
Properly set up the DeclContext for parameters of implicit deduction guides;
this is needed for deferred instantiation of default arguments. llvm-svn: 295379
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp9
-rw-r--r--clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp8
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);
+}
OpenPOWER on IntegriCloud