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/SemaCodeComplete.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/SemaCodeComplete.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 700f5a2fee2..ae5183408f1 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -1303,8 +1303,33 @@ namespace { void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override { bool Accessible = true; - if (Ctx) - Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); + if (Ctx) { + DeclContext *AccessingCtx = Ctx; + // If ND comes from a base class, set the naming class back to the + // derived class if the search starts from the derived class (i.e. + // InBaseClass is true). + // + // Example: + // class B { protected: int X; } + // class D : public B { void f(); } + // void D::f() { this->^; } + // The completion after "this->" will have `InBaseClass` set to true and + // `Ctx` set to "B", when looking up in `B`. We need to set the actual + // accessing context (i.e. naming class) to "D" so that access can be + // calculated correctly. + if (InBaseClass && isa<CXXRecordDecl>(Ctx)) { + CXXRecordDecl *RC = nullptr; + // Get the enclosing record. + for (DeclContext *DC = CurContext; !DC->isFileContext(); + DC = DC->getParent()) { + if ((RC = dyn_cast<CXXRecordDecl>(DC))) + break; + } + if (RC) + AccessingCtx = RC; + } + Accessible = Results.getSema().IsSimplyAccessible(ND, AccessingCtx); + } ResultBuilder::Result Result(ND, Results.getBasePriority(ND), nullptr, false, Accessible, FixIts); |