summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCodeComplete.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp29
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);
OpenPOWER on IntegriCloud