diff options
author | Eric Liu <ioeric@google.com> | 2018-07-19 13:32:00 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-07-19 13:32:00 +0000 |
commit | 18b404a52177363aefb6c199bdda995a75bb8388 (patch) | |
tree | 12bbe8bb7cda196dfbdcb1fb9473adc7837b32d2 /clang/lib/Sema/SemaAccess.cpp | |
parent | 67b8f573a76ec3e03e3227061541276e797376eb (diff) | |
download | bcm5719-llvm-18b404a52177363aefb6c199bdda995a75bb8388.tar.gz bcm5719-llvm-18b404a52177363aefb6c199bdda995a75bb8388.zip |
[CodeComplete] Fix accessibilty of protected members from base class.
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].
Reviewers: aaron.ballman, sammccall, rsmith
Reviewed By: aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D49421
llvm-svn: 337453
Diffstat (limited to 'clang/lib/Sema/SemaAccess.cpp')
-rw-r--r-- | clang/lib/Sema/SemaAccess.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 44d41ea4b05..9fbae2ca297 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/Specifiers.h" #include "clang/Sema/SemaInternal.h" #include "clang/AST/ASTContext.h" #include "clang/AST/CXXInheritance.h" @@ -1856,29 +1857,31 @@ void Sema::CheckLookupAccess(const LookupResult &R) { } } -/// Checks access to Decl from the given class. The check will take access +/// Checks access to Target from the given class. The check will take access /// specifiers into account, but no member access expressions and such. /// -/// \param Decl the declaration to check if it can be accessed +/// \param Target the declaration to check if it can be accessed /// \param Ctx the class/context from which to start the search -/// \return true if the Decl is accessible from the Class, false otherwise. -bool Sema::IsSimplyAccessible(NamedDecl *Decl, DeclContext *Ctx) { +/// \return true if the Target is accessible from the Class, false otherwise. +bool Sema::IsSimplyAccessible(NamedDecl *Target, DeclContext *Ctx) { if (CXXRecordDecl *Class = dyn_cast<CXXRecordDecl>(Ctx)) { - if (!Decl->isCXXClassMember()) + if (!Target->isCXXClassMember()) return true; + if (Target->getAccess() == AS_public) + return true; QualType qType = Class->getTypeForDecl()->getCanonicalTypeInternal(); + // The unprivileged access is AS_none as we don't know how the member was + // accessed, which is described by the access in DeclAccessPair. + // `IsAccessible` will examine the actual access of Target (i.e. + // Decl->getAccess()) when calculating the access. AccessTarget Entity(Context, AccessedEntity::Member, Class, - DeclAccessPair::make(Decl, Decl->getAccess()), - qType); - if (Entity.getAccess() == AS_public) - return true; - + DeclAccessPair::make(Target, AS_none), qType); EffectiveContext EC(CurContext); return ::IsAccessible(*this, EC, Entity) != ::AR_inaccessible; } - - if (ObjCIvarDecl *Ivar = dyn_cast<ObjCIvarDecl>(Decl)) { + + if (ObjCIvarDecl *Ivar = dyn_cast<ObjCIvarDecl>(Target)) { // @public and @package ivars are always accessible. if (Ivar->getCanonicalAccessControl() == ObjCIvarDecl::Public || Ivar->getCanonicalAccessControl() == ObjCIvarDecl::Package) |