public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: David Malcolm <dmalcolm@redhat.com>, gcc-patches@gcc.gnu.org
Cc: Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH] C++: fix-it hints suggesting accessors for private fields
Date: Thu, 27 Apr 2017 12:32:00 -0000	[thread overview]
Message-ID: <9a66ceee-2f5e-cb43-2939-4f9ebf7105b3@acm.org> (raw)
In-Reply-To: <1493224456.9106.151.camel@redhat.com>

On 04/26/2017 12:34 PM, David Malcolm wrote:

> Thanks - yes; that gives information on the const vs non-const of the
> "this" parameter, but doesn't say whether the argument was const vs non
> -const.

> However, within:
> 
> int test_const_ptr (const t1 *ptr)
> {
>    return ptr->m_color;
> }
> from which we can see the const-ness of the t1:

correct.

> but the call to lookup_member from within
> finish_class_member_access_expr discards this information, giving just
> "access_path": a BINFO that wraps the RECORD_TYPE for t1 directly.

Correct.

lookup_member just looks for a matching name.  the BINFO represents the 
class hierarchy - it's not modified depending on the cvquals of where 
you came from.

> A somewhat invasive solution would be for lookup_member to grow an extra:
>    tree object
> parameter, and to pass this information down through the access
> -enforcement code, so that locate_field_accessor can look at the const
> -ness of the lookup, and avoid suggesting const methods when the object
> is const.  The code would probably need to support the new param being
> NULL_TREE for cases where we're looking up a static member.  Or maybe
> an enum of access style for const vs non-const vs static.
> Maybe name the param "access_hint" to signify that it's merely there
> for the purpose of hints for the user, and not to affect the parsing
> itself?

Hm, that does seem rather unfortunate.
> Another solution would be to not bother offering non-const methods as
> accessors.

I think that would be very unfortunate.

How about adding a tsubst_flag value?

   tf_const_obj = 1 << 11, /* For alternative accessor suggestion help.  */

and pass that in?  the tsubst flags have grown in meaning somewhat since 
they first appeared -- their name is no longer so appropriate.

(of course we have the same problem with volatile, but that's probably 
overkill for first attempt.)

Jason, WDYT?

nathan

-- 
Nathan Sidwell

  reply	other threads:[~2017-04-27 11:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 20:34 David Malcolm
2017-04-25 11:51 ` Nathan Sidwell
2017-04-25 12:01   ` Nathan Sidwell
2017-04-25 16:11     ` David Malcolm
2017-04-25 16:14       ` Nathan Sidwell
2017-04-25 22:17         ` David Malcolm
2017-04-26  4:05           ` Nathan Sidwell
2017-04-26 17:58             ` David Malcolm
2017-04-27 12:32               ` Nathan Sidwell [this message]
2017-05-01 18:43                 ` Jason Merrill
2017-05-05 23:26                   ` [PATCH v2] " David Malcolm
2017-05-16 18:04                     ` 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=9a66ceee-2f5e-cb43-2939-4f9ebf7105b3@acm.org \
    --to=nathan@acm.org \
    --cc=dmalcolm@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).