]> granicus.if.org Git - clang/commitdiff
Once we've collected the template arguments for a
authorDouglas Gregor <dgregor@apple.com>
Fri, 18 Jan 2013 22:27:09 +0000 (22:27 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 18 Jan 2013 22:27:09 +0000 (22:27 +0000)
partially-substituted parameter pack in a template, forget about the
partially-substituted parameter pack: it is now completed. Fixes
<rdar://problem/12176336>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172859 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Template.h
lib/Sema/SemaTemplateDeduction.cpp
test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-0x.cpp

index 13c44718582c5c5700df49a00fc5d18a0aa9bbb3..fd67222f0f8e8ad44fb749def00b59b39a0a6954 100644 (file)
@@ -345,7 +345,16 @@ namespace clang {
     void SetPartiallySubstitutedPack(NamedDecl *Pack, 
                                      const TemplateArgument *ExplicitArgs,
                                      unsigned NumExplicitArgs);
-    
+
+    /// \brief Reset the partially-substituted pack when it is no longer of
+    /// interest.
+    void ResetPartiallySubstitutedPack() {
+      assert(PartiallySubstitutedPack && "No partially-substituted pack");
+      PartiallySubstitutedPack = 0;
+      ArgsInPartiallySubstitutedPack = 0;
+      NumArgsInPartiallySubstitutedPack = 0;
+    }
+
     /// \brief Retrieve the partially-substitued template parameter pack.
     ///
     /// If there is no partially-substituted parameter pack, returns NULL.
index 67ea68928da6748eba240af6a47c1694839501e6..00a48e9396b2f0323da1fcfa11f09ae8d863fe50 100644 (file)
@@ -2647,11 +2647,15 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
       if (CurrentInstantiationScope &&
           CurrentInstantiationScope->getPartiallySubstitutedPack(&ExplicitArgs,
                                                              &NumExplicitArgs)
-          == Param)
+            == Param) {
         Builder.push_back(TemplateArgument(ExplicitArgs, NumExplicitArgs));
-      else
-        Builder.push_back(TemplateArgument::getEmptyPack());
 
+        // Forget the partially-substituted pack; it's substitution is now
+        // complete.
+        CurrentInstantiationScope->ResetPartiallySubstitutedPack();
+      } else {
+        Builder.push_back(TemplateArgument::getEmptyPack());
+      }
       continue;
     }
 
index 36b07002cf3d82dfe7a3e9c43d85543ff1022b51..dcf5a08d906290a548247f0f3acd38fa11cfa52c 100644 (file)
@@ -26,3 +26,24 @@ namespace ParameterPacksWithFunctions {
     unsigned_c<2> uc2 = f<float, double>();
   }
 }
+
+namespace rdar12176336 {
+  typedef void (*vararg_func)(...);
+
+  struct method {
+    vararg_func implementation;
+       
+    method(vararg_func implementation) : implementation(implementation) {}
+       
+    template<typename TReturnType, typename... TArguments, typename TFunctionType = TReturnType (*)(TArguments...)>
+    auto getImplementation() const -> TFunctionType
+    {
+      return reinterpret_cast<TFunctionType>(implementation);
+    }
+  };
+
+  void f() {
+    method m(nullptr);
+    auto imp = m.getImplementation<int, int, int>();
+  }
+}