public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: wrong ambiguity in accessing static field [PR112744]
Date: Wed, 29 Nov 2023 16:59:57 -0500	[thread overview]
Message-ID: <ZWe0XakB7Ru6lDMk@redhat.com> (raw)
In-Reply-To: <80a8828a-2abc-478d-b65a-fcb631ca45fd@redhat.com>

On Wed, Nov 29, 2023 at 01:58:31PM -0500, Jason Merrill wrote:
> On 11/29/23 10:45, Marek Polacek wrote:
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > 
> > Now that I'm posting this patch, I think you'll probably want me to use
> > ba_any unconditionally.  That works too; g++.dg/tc1/dr52.C just needs
> > a trivial testsuite tweak:
> >    'C' is not an accessible base of 'X'
> > v.
> >    'C' is an inaccessible base of 'X'
> > We should probably unify those messages...
> 
> Hmm, won't using ba_any unconditionally break ambiguous base checking for
> non-static data members?

Yes.  I thought not but that's only because we weren't properly testing
that case (added scoped14.C, patch to follow).  So that settles that.
 
> > @@ -3493,9 +3493,24 @@ finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
> >   	      return error_mark_node;
> >   	    }
> > +	  /* NAME may refer to a static data member, in which case there is
> > +	     one copy of the data member that is shared by all the objects of
> > +	     the class.  So NAME can be unambiguously referred to even if
> > +	     there are multiple indirect base classes containing NAME.  */
> > +	  const base_access ba = [scope, name] ()
> 
> Why a lambda?

Only so that I can set 'ba' once and make it const.  I don't believe it
deserves a named function.  It seems more readable than using a ?:.

> > +	    {
> > +	      if (identifier_p (name))
> > +		{
> > +		  tree m = lookup_member (scope, name, /*protect=*/0,
> > +					  /*want_type=*/false, tf_none);
> > +		  if (!m || VAR_P (m))
> 
> Do you want shared_member_p here?

That looks like the right thing to use, thanks.

Marek


      reply	other threads:[~2023-11-29 22:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29 15:45 Marek Polacek
2023-11-29 17:23 ` Patrick Palka
2023-11-29 17:43   ` Marek Polacek
2023-11-29 20:28     ` Jason Merrill
2023-11-29 22:01       ` [PATCH v2] " Marek Polacek
2023-11-30 16:42         ` Jason Merrill
2023-11-30 21:44           ` Marek Polacek
2023-11-29 18:58 ` [PATCH] " Jason Merrill
2023-11-29 21:59   ` Marek Polacek [this message]

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=ZWe0XakB7Ru6lDMk@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /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).