From: Douglas Gregor Date: Fri, 18 Jan 2013 22:27:09 +0000 (+0000) Subject: Once we've collected the template arguments for a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=22eaced5cac3cf0522c953f593419fc6cf184aaf;p=clang Once we've collected the template arguments for a partially-substituted parameter pack in a template, forget about the partially-substituted parameter pack: it is now completed. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172859 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Template.h b/include/clang/Sema/Template.h index 13c4471858..fd67222f0f 100644 --- a/include/clang/Sema/Template.h +++ b/include/clang/Sema/Template.h @@ -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. diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 67ea68928d..00a48e9396 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -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; } diff --git a/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-0x.cpp b/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-0x.cpp index 36b07002cf..dcf5a08d90 100644 --- a/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-0x.cpp +++ b/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-0x.cpp @@ -26,3 +26,24 @@ namespace ParameterPacksWithFunctions { unsigned_c<2> uc2 = f(); } } + +namespace rdar12176336 { + typedef void (*vararg_func)(...); + + struct method { + vararg_func implementation; + + method(vararg_func implementation) : implementation(implementation) {} + + template + auto getImplementation() const -> TFunctionType + { + return reinterpret_cast(implementation); + } + }; + + void f() { + method m(nullptr); + auto imp = m.getImplementation(); + } +}