On 3/23/23 17:18, Patrick Palka wrote:
Here we're issuing a duplicate diagnostic for the use of the deleted
foo, first from the CALL_EXPR case of tsubst_copy_and_build (which
doesn't exit early upon failure), and again from from build_over_call
when rebuilding the substituted CALL_EXPR.

We can fix this by exiting early upon failure of the first call, but
this first call should always be redundant since build_over_call (or
another subroutine of finish_call_expr) ought to reliably call mark_used
for a suitable DECL_P callee anyway.

So this patch just gets rid of the first call to mark_used.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?

OK.

        PR c++/106880

gcc/cp/ChangeLog:

        * pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Don't call
        mark_used.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp0x/deleted16.C: New test.
---
  gcc/cp/pt.cc                           |  6 ------
  gcc/testsuite/g++.dg/cpp0x/deleted16.C | 11 +++++++++++
  2 files changed, 11 insertions(+), 6 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/deleted16.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 9b3cc33331c..060d2d38504 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21176,12 +21176,6 @@ tsubst_copy_and_build (tree t,
              }
          }
- /* Remember that there was a reference to this entity. */
-       if (function != NULL_TREE
-           && DECL_P (function)
-           && !mark_used (function, complain) && !(complain & tf_error))
-         RETURN (error_mark_node);
-
        if (!maybe_fold_fn_template_args (function, complain))
          return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted16.C b/gcc/testsuite/g++.dg/cpp0x/deleted16.C
new file mode 100644
index 00000000000..93cfb51eb3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/deleted16.C
@@ -0,0 +1,11 @@
+// PR c++/106880
+// Verify we don't emit a "use of deleted function" diagnostic twice.
+// { dg-do compile { target c++11 } }
+
+void foo() = delete;
+
+template<class T>
+void f(T t) { foo(t); } // { dg-bogus "deleted function.*deleted function" }
+                        // { dg-error "deleted function" "" { target *-*-*} 
.-1 }
+
+template void f(int);

Reply via email to