]> granicus.if.org Git - clang/commitdiff
Properly set up the DeclContext for parameters of implicit deduction guides;
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 16 Feb 2017 21:29:21 +0000 (21:29 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 16 Feb 2017 21:29:21 +0000 (21:29 +0000)
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

lib/Sema/SemaTemplate.cpp
test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

index 5470017303de74317c8e53a3c28596b13843b9ff..4c5f3bee15b10ce3fc53ea530abef08c137dd3bd 100644 (file)
@@ -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);
index 3d256aa67050136a4e73316a2824746093d367d0..1205fd1cf3d1a25e30369d69182d69e6fe020ba7 100644 (file)
@@ -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);
+}