]> granicus.if.org Git - clang/commitdiff
[c++17] When deducing the type of a non-type template parameter from the type
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Dec 2017 21:24:36 +0000 (21:24 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Dec 2017 21:24:36 +0000 (21:24 +0000)
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
test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

index 51f21be64a882f4b4921b6824b84c15afbdb4cd0..a91c190cb0c2bba5205af1a958bc8a1667aaf342 100644 (file)
@@ -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<PackExpansionType>(ParamType))
     ParamType = Expansion->getPattern();
 
index d0fb25c047a9610fe4f3995a53047877031b775b..1a84d545c647448487cbb0094e0ca162b4d6dd83 100644 (file)
@@ -238,6 +238,10 @@ namespace Auto {
     constexpr char s[] = "test";
     template<const auto* p> struct S { };
     S<s> p;
+
+    template<typename R, typename P, R F(P)> struct A {};
+    template<typename R, typename P, R F(P)> void x(A<R, P, F> a);
+    void g(int) { x(A<void, int, &g>()); }
   }
 
   namespace DecltypeAuto {