[PATCH] D52647: [CodeComplete] Re-fix accessibilty of protected members from base class.

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 03:32:28 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL343575: [CodeComplete] Re-fix accessibilty of protected members from base class. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52647

Files:
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/test/Index/complete-access-checks.cpp


Index: cfe/trunk/test/Index/complete-access-checks.cpp
===================================================================
--- cfe/trunk/test/Index/complete-access-checks.cpp
+++ cfe/trunk/test/Index/complete-access-checks.cpp
@@ -36,10 +36,10 @@
 
 // CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34)
 // CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{Informative X::}{TypedText func1}{LeftParen (}{RightParen )} (36)
-// CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{Informative X::}{TypedText func2}{LeftParen (}{RightParen )} (36)
+// CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{Informative X::}{TypedText func2}{LeftParen (}{RightParen )} (36){{$}}
 // CHECK-SUPER-ACCESS: CXXMethod:{ResultType void}{Informative X::}{TypedText func3}{LeftParen (}{RightParen )} (36) (inaccessible)
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member1} (37)
-// CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member2} (37)
+// CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member2} (37){{$}}
 // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member3} (37) (inaccessible)
 // CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (79)
 // CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (81)
Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/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 @@
     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 @@
   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,
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -3619,8 +3619,9 @@
 
       // 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);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52647.167911.patch
Type: text/x-patch
Size: 4890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181002/09e66fff/attachment-0001.bin>


More information about the cfe-commits mailing list