c++: auto function as function argument [PR105779]
authorJason Merrill <jason@redhat.com>
Tue, 31 May 2022 20:17:58 +0000 (16:17 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 1 Jun 2022 19:53:24 +0000 (15:53 -0400)
This testcase demonstrates that the issue in PR105623 is not limited to
templates, so we should do the marking in a less template-specific place.

PR c++/105779

gcc/cp/ChangeLog:

* call.cc (resolve_args): Call mark_single_function here.
* pt.cc (unify_one_argument): Not here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/auto-fn63.C: New test.

gcc/cp/call.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1y/auto-fn63.C [new file with mode: 0644]

index fa18d7f..45253b1 100644 (file)
@@ -4672,6 +4672,11 @@ resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
        }
       else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
        return NULL;
+
+      /* Force auto deduction now.  Omit tf_warning to avoid redundant
+        deprecated warning on deprecated-14.C.  */
+      if (!mark_single_function (arg, tf_error))
+       return NULL;
     }
   return args;
 }
index 1c1b0e3..e036f01 100644 (file)
@@ -22656,10 +22656,6 @@ unify_one_argument (tree tparms, tree targs, tree parm, tree arg,
              return unify_success (explain_p);
            }
 
-         /* Force auto deduction now.  Use tf_none to avoid redundant
-            deprecated warning on deprecated-14.C.  */
-         mark_single_function (arg, tf_none);
-
          arg_expr = arg;
          arg = unlowered_expr_type (arg);
          if (arg == error_mark_node)
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn63.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn63.C
new file mode 100644 (file)
index 0000000..ca3bc85
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/105779
+// { dg-do compile { target c++14 } }
+
+template<int>
+struct struct1
+{
+  static auto apply() { return 1; }
+};
+
+int method(int(*f)());
+
+int t = method(struct1<1>::apply);