public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] c++: further lookup_member simplification
Date: Tue, 15 Mar 2022 13:18:39 -0400	[thread overview]
Message-ID: <20220315171839.1872125-1-ppalka@redhat.com> (raw)

As a followup to r12-7656-gffe9c0a0d3564a, this minor patch condenses
the handling of ambiguity and access w.r.t. the value of 'protect' so
that it more clearly matches the function comment.

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

gcc/cp/ChangeLog:

	* search.cc (lookup_member): Simplify by handling all values
	of protect at once in case of ambiguous lookup.  Don't modify
	protect.
---
 gcc/cp/search.cc | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc
index 85e3e7cb487..b86b3a24080 100644
--- a/gcc/cp/search.cc
+++ b/gcc/cp/search.cc
@@ -1168,27 +1168,21 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type,
   if (rval_binfo)
     type = BINFO_TYPE (rval_binfo);
 
-  /* If we are not interested in ambiguities, don't report them;
-     just return NULL_TREE.  */
-  if (!protect && lfi.ambiguous)
-    return NULL_TREE;
-
-  if (protect == 2)
-    {
-      if (lfi.ambiguous)
-	return lfi.ambiguous;
-      else
-	protect = 0;
-    }
-
-  if (protect == 1 && lfi.ambiguous)
+  if (lfi.ambiguous)
     {
-      if (complain & tf_error)
+      if (protect == 0)
+	return NULL_TREE;
+      else if (protect == 1)
 	{
-	  error ("request for member %qD is ambiguous", name);
-	  print_candidates (lfi.ambiguous);
+	  if (complain & tf_error)
+	    {
+	      error ("request for member %qD is ambiguous", name);
+	      print_candidates (lfi.ambiguous);
+	    }
+	  return error_mark_node;
 	}
-      return error_mark_node;
+      else if (protect == 2)
+	return lfi.ambiguous;
     }
 
   if (!rval)
@@ -1213,7 +1207,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type,
 
     only the first call to "f" is valid.  However, if the function is
     static, we can check.  */
-  if (protect && !really_overloaded_fn (rval))
+  if (protect == 1 && !really_overloaded_fn (rval))
     {
       tree decl = is_overloaded_fn (rval) ? get_first_fn (rval) : rval;
       decl = strip_using_decl (decl);
-- 
2.35.1.500.gb896f729e2


             reply	other threads:[~2022-03-15 17:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 17:18 Patrick Palka [this message]
2022-03-15 21:06 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220315171839.1872125-1-ppalka@redhat.com \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).