This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] C++: fix-it hints suggesting accessors for private fields


On 04/25/2017 07:46 AM, Nathan Sidwell wrote:
On 04/24/2017 04:06 PM, David Malcolm wrote:

test.cc:12:13: note: field ‘int foo::m_field’ can be accessed via ‘int foo::get_field() const’
    return f->m_field;
              ^~~~~~~
              get_field()

Assuming that an IDE can offer to apply fix-it hints, this should
make it easier to handle refactorings where one makes a field
private and adds a getter.

It also helps by letting the user know that a getter exists, and
the name of the getter ("is it "field", "get_field", etc?").

Neat!


OK for trunk?

gcc/cp/ChangeLog:
    * call.c (maybe_suggest_accessor): New function.
    (enforce_access): Call maybe_suggest_accessor for inaccessible
    decls.
    * cp-tree.h (locate_field_accessor): New decl.
    * search.c (matches_code_and_type_p): New function.
    (field_access_p): New function.
    (direct_accessor_p): New function.
    (reference_accessor_p): New function.
    (field_accessor_p): New function.
    (dfs_locate_field_accessor_pre): New function.
    (locate_field_accessor): New function.

ok.

Oh, what if the field is being accessed for modification or lvalueness? Must the accessor return T, or can it return 'T cv &'? I.e. does it need to look for setters too?

nathan
--
Nathan Sidwell


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]