diff options
| author | Eric Liu <ioeric@google.com> | 2018-10-02 10:29:00 +0000 |
|---|---|---|
| committer | Eric Liu <ioeric@google.com> | 2018-10-02 10:29:00 +0000 |
| commit | b91e08197cf74c1c2d92f0fc112e941f8ef883a1 (patch) | |
| tree | cb19afb931facbf4ed2947466f97bb70139c2079 /clang/lib/Sema | |
| parent | b9e17124ea24d7e83ddae68f8e05f632e7b7a28a (diff) | |
| download | bcm5719-llvm-b91e08197cf74c1c2d92f0fc112e941f8ef883a1.tar.gz bcm5719-llvm-b91e08197cf74c1c2d92f0fc112e941f8ef883a1.zip | |
[CodeComplete] Re-fix accessibilty of protected members from base class.
Summary:
The initial fix (r337453) had bug and was partially reverted (r338255).
This simplies the original fix by explicitly passing the naming class to the
completion consumer.
Reviewers: ilya-biryukov
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D52647
llvm-svn: 343575
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 23 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 5 |
2 files changed, 21 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 1251c76f3a1..33bb1229ac1 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -10,6 +10,7 @@ // This file defines the code-completion semantic actions. // //===----------------------------------------------------------------------===// +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" @@ -1295,18 +1296,29 @@ namespace { ResultBuilder &Results; DeclContext *CurContext; std::vector<FixItHint> FixIts; + // This is set to the record where the search starts, if this is a record + // member completion. + RecordDecl *MemberCompletionRecord = nullptr; public: CodeCompletionDeclConsumer( ResultBuilder &Results, DeclContext *CurContext, - std::vector<FixItHint> FixIts = std::vector<FixItHint>()) - : Results(Results), CurContext(CurContext), FixIts(std::move(FixIts)) {} + std::vector<FixItHint> FixIts = std::vector<FixItHint>(), + RecordDecl *MemberCompletionRecord = nullptr) + : Results(Results), CurContext(CurContext), FixIts(std::move(FixIts)), + MemberCompletionRecord(MemberCompletionRecord) {} void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override { bool Accessible = true; - if (Ctx) - Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); + if (Ctx) { + // Set the actual accessing context (i.e. naming class) to the record + // context where the search starts. When `InBaseClass` is true, `Ctx` + // will be the base class, which is not the actual naming class. + DeclContext *AccessingCtx = + MemberCompletionRecord ? MemberCompletionRecord : Ctx; + Accessible = Results.getSema().IsSimplyAccessible(ND, AccessingCtx); + } ResultBuilder::Result Result(ND, Results.getBasePriority(ND), nullptr, false, Accessible, FixIts); Results.AddResult(Result, CurContext, Hiding, InBaseClass); @@ -4101,7 +4113,8 @@ static void AddRecordMembersCompletionResults(Sema &SemaRef, std::vector<FixItHint> FixIts; if (AccessOpFixIt) FixIts.emplace_back(AccessOpFixIt.getValue()); - CodeCompletionDeclConsumer Consumer(Results, SemaRef.CurContext, std::move(FixIts)); + CodeCompletionDeclConsumer Consumer(Results, SemaRef.CurContext, + std::move(FixIts), RD); SemaRef.LookupVisibleDecls(RD, Sema::LookupMemberName, Consumer, SemaRef.CodeCompleter->includeGlobals(), /*IncludeDependentBases=*/true, diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 6a1aae62413..8cb0fb4cb88 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -3619,8 +3619,9 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, // Find results in this base class (and its bases). ShadowContextRAII Shadow(Visited); - LookupVisibleDecls(RD, Result, QualifiedNameLookup, true, Consumer, - Visited, IncludeDependentBases, LoadExternal); + LookupVisibleDecls(RD, Result, QualifiedNameLookup, /*InBaseClass=*/true, + Consumer, Visited, IncludeDependentBases, + LoadExternal); } } |

