From 5a9220e6798f1052bbdb4cfa96711fa5ce2f00e9 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 1 Dec 2017 21:24:36 +0000 Subject: [PATCH] [c++17] When deducing the type of a non-type template parameter from the type of its argument, perform function-to-pointer and array-to-pointer decay on the parameter type first. Otherwise deduction will fail, as the type of the argument will be decayed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319584 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateDeduction.cpp | 5 +++-- test/SemaTemplate/temp_arg_nontype_cxx1z.cpp | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 51f21be64a..a91c190cb0 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -354,8 +354,9 @@ static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument( // expanded NTTP should be a pack expansion type? return Sema::TDK_Success; - // Get the type of the parameter for deduction. - QualType ParamType = NTTP->getType(); + // Get the type of the parameter for deduction. If it's a (dependent) array + // or function type, we will not have decayed it yet, so do that now. + QualType ParamType = S.Context.getAdjustedParameterType(NTTP->getType()); if (auto *Expansion = dyn_cast(ParamType)) ParamType = Expansion->getPattern(); diff --git a/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp b/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp index d0fb25c047..1a84d545c6 100644 --- a/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ b/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -238,6 +238,10 @@ namespace Auto { constexpr char s[] = "test"; template struct S { }; S p; + + template struct A {}; + template void x(A a); + void g(int) { x(A()); } } namespace DecltypeAuto { -- 2.50.1