This is an archive of the discontinued LLVM Phabricator instance.

[CodeComplete] Fix accessibilty of protected members from base class.
ClosedPublic

Authored by ioeric on Jul 17 2018, 5:48 AM.

Details

Summary

Currently, protected members from base classes are marked as
inaccessible when completing in derived class. This patch fixes the problem by
setting the naming class correctly when looking up results in base class
according to [11.2.p5].

Diff Detail

Repository
rC Clang

Event Timeline

ioeric created this revision.Jul 17 2018, 5:48 AM

Adding Richard to see if he agrees with the direction taken.

lib/Sema/SemaAccess.cpp
1874–1876

This seems to contradict the function-level comment that says the check seems to only take the access specifiers into account and not how the member is accessed.

lib/Sema/SemaCodeComplete.cpp
1307

Please do not use auto as the type is not spelled out in the initialization.

1316–1317

This makes it sound like the caller has messed something up, but I'm also pretty unfamiliar with the code completion logic. Why would InBaseClass be true for that completion point and why would the context be set to B?

1319

You can drop the llvm::

1322

Please don't use auto here either.

1324

You can drop the llvm::

ioeric updated this revision to Diff 156056.Jul 18 2018, 5:49 AM
ioeric marked 4 inline comments as done.
  • addressed review comments.

Thanks for the review!

lib/Sema/SemaAccess.cpp
1874–1876

not how the member is accessed.

It's not very clear to me what exactly this means. But I think we are still not taking how member was accessed into account. The access in DeclAccessPair describes how a member was accessed, and this should be None instead of the access specifier of the member as we don't have this information here.

I updated the wording in the comment to make this a bit clearer.

lib/Sema/SemaCodeComplete.cpp
1316–1317

It's a bit messy, but this is roughly how lookup inside a class, say D,works:

  1. lookup inside the class (InBaseClass = false, Context=D).
  2. Run the same lookup on all base classes (InBaseClass=true, Context=B). (https://github.com/llvm-mirror/clang/blob/master/lib/Sema/SemaLookup.cpp#L3584)

So, InBaseClass would be true when a lookup starts from a derived class.

aaron.ballman added inline comments.Jul 18 2018, 12:26 PM
lib/Sema/SemaAccess.cpp
1874–1876

I'm still wondering about the removal of the public access check -- if the declaration has a public access specifier, that early return saves work. So Entity may still require passing AS_none but we might want to continue to check Decl->getAccess() == AS_public for the early return?

(Drive-by nit that's not yours: Decl is the name of a type, so if you wanted to rename the parameter to something that isn't a type name, I would not be sad, but you're not required to do it.)

lib/Sema/SemaCodeComplete.cpp
1316–1317

Ah, thank you for the explanation; that helps.

ioeric updated this revision to Diff 156146.Jul 18 2018, 1:35 PM
ioeric marked an inline comment as done.
  • addressed review comments.
  • Addressed review comments.
ioeric added inline comments.Jul 18 2018, 1:35 PM
lib/Sema/SemaAccess.cpp
1874–1876

Added Decl->getAccess() == AS_public back to preserve the behavior.

s/Decl/Target/

This revision is now accepted and ready to land.Jul 19 2018, 5:48 AM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.