On 2/27/22 18:52, Jason Merrill wrote:
The patch for PR90451 deferred marking to the point of actual use; we missed
this one because of the parens.

Tested x86_64-pc-linux-gnu, applying to trunk.

        PR c++/104618

gcc/cp/ChangeLog:

        * typeck.cc (cp_build_addr_expr_1): Also
        maybe_undo_parenthesized_ref.

gcc/testsuite/ChangeLog:

        * g++.dg/overload/paren1.C: New test.
---
  gcc/cp/typeck.cc                       | 6 +++---
  gcc/testsuite/g++.dg/overload/paren1.C | 7 +++++++
  2 files changed, 10 insertions(+), 3 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/overload/paren1.C

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index f796337f73c..bddc83759ad 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -6884,9 +6884,9 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, 
tsubst_flags_t complain)
       so we can just form an ADDR_EXPR with the correct type.  */
    if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
      {
-      tree stripped_arg = tree_strip_any_location_wrapper (arg);
-      if (TREE_CODE (stripped_arg) == FUNCTION_DECL
-         && !mark_used (stripped_arg, complain) && !(complain & tf_error))
+      tree stripped_arg
+       = tree_strip_any_location_wrapper (maybe_undo_parenthesized_ref (arg));
+      if (!mark_single_function (stripped_arg, complain))

It occurred to me that it would be cleaner to do the stripping in mark_single_function.

From efea883ae8a912f9e1081abf51b1e581232e5f30 Mon Sep 17 00:00:00 2001
From: Jason Merrill <ja...@redhat.com>
Date: Mon, 28 Feb 2022 12:05:34 -0400
Subject: [PATCH] c++: tweak to (*(fn))() patch [PR104618]
To: gcc-patches@gcc.gnu.org

Other callers of mark_single_function might also want to look through these
wrapapers.

	PR c++/104618

gcc/cp/ChangeLog:

	* decl2.cc (mark_single_function): Look through parens and location
	wrapper.
	* typeck.cc (cp_build_addr_expr_1): Not here.
---
 gcc/cp/decl2.cc  | 3 +++
 gcc/cp/typeck.cc | 4 +---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 22edc2ba7f9..e85bb87c955 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -5737,6 +5737,9 @@ decl_dependent_p (tree decl)
 bool
 mark_single_function (tree expr, tsubst_flags_t complain)
 {
+  expr = maybe_undo_parenthesized_ref (expr);
+  expr = tree_strip_any_location_wrapper (expr);
+
   if (is_overloaded_fn (expr) == 1
       && !mark_used (expr, complain)
       && (complain & tf_error))
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index bddc83759ad..ea6a485bbbf 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -6884,9 +6884,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
      so we can just form an ADDR_EXPR with the correct type.  */
   if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
     {
-      tree stripped_arg
-	= tree_strip_any_location_wrapper (maybe_undo_parenthesized_ref (arg));
-      if (!mark_single_function (stripped_arg, complain))
+      if (!mark_single_function (arg, complain))
 	return error_mark_node;
       val = build_address (arg);
       if (TREE_CODE (arg) == OFFSET_REF)
-- 
2.27.0

Reply via email to