]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: NTTP with array/function type after substitution [PR61355]
authorPatrick Palka <ppalka@redhat.com>
Thu, 7 Oct 2021 20:39:16 +0000 (16:39 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 7 Oct 2021 20:39:16 +0000 (16:39 -0400)
We're performing the [temp.param]/10 adjustment at parse time but not
also at substitution time.

PR c++/61355

gcc/cp/ChangeLog:

* pt.c (convert_template_argument): Perform array/function to
pointer conversion on the substituted type of an NTTP.

gcc/testsuite/ChangeLog:

* g++.old-deja/g++.pt/nontype5.C: Adjust.
* g++.dg/template/param6.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.dg/template/param6.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.pt/nontype5.C

index 1e52aa757e1b7165197758b17a5d24375251ac9c..009fe6db573f08b792c0a861a3a84024a90b7573 100644 (file)
@@ -8530,6 +8530,10 @@ convert_template_argument (tree parm,
       else
        t = tsubst (t, args, complain, in_decl);
 
+      /* Perform array-to-pointer and function-to-pointer conversion
+        as per [temp.param]/10.  */
+      t = type_decays_to (t);
+
       if (invalid_nontype_parm_type_p (t, complain))
        return error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/template/param6.C b/gcc/testsuite/g++.dg/template/param6.C
new file mode 100644 (file)
index 0000000..8306e75
--- /dev/null
@@ -0,0 +1,32 @@
+// PR c++/61355
+// Verify we perform array-to-pointer and function-to-pointer conversion
+// on the substituted/deduced type of an NTTP.
+
+int f();
+int p[5];
+
+namespace cpp98 {
+  template<class T, T> struct X;
+  typedef X<int(), f> ty1;
+  typedef X<int[5], p> ty2;
+}
+
+namespace cpp11 {
+#if __cpp_variadic_templates
+  template<class T, T...> struct X;
+  using ty1 = X<int(), f>;
+  using ty2 = X<int[5], p>;
+#endif
+}
+
+namespace cpp17 {
+#if __cpp_nontype_template_parameter_auto
+  template<decltype(auto)> struct X;
+  using ty1 = X<f>;
+  using ty2 = X<p>;
+
+  template<decltype(auto)...> struct Y;
+  using ty3 = Y<f>;
+  using ty4 = Y<p>;
+#endif
+}
index 2678cf78a7d56008adf229d2d9eaddd79ca5481f..e24dca4362217da6507411f2e897eca4e57a7147 100644 (file)
@@ -19,5 +19,5 @@ static int g() { return f(); }
 int f() { return 0; }
 
 int main() {
-return B<int,&f>::g();  // { dg-error "" } could not convert arg
+return B<int,&f>::g();
 }