r247207 - Fix access control for lookups using the Microsoft __super extension.

John McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 9 16:04:17 PDT 2015


Author: rjmccall
Date: Wed Sep  9 18:04:17 2015
New Revision: 247207

URL: http://llvm.org/viewvc/llvm-project?rev=247207&view=rev
Log:
Fix access control for lookups using the Microsoft __super extension.

rdar://22464808

Added:
    cfe/trunk/test/SemaCXX/microsoft-super.cpp
Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=247207&r1=247206&r2=247207&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Sep  9 18:04:17 2015
@@ -2098,17 +2098,30 @@ bool Sema::LookupParsedName(LookupResult
 ///
 /// @returns True if any decls were found (but possibly ambiguous)
 bool Sema::LookupInSuper(LookupResult &R, CXXRecordDecl *Class) {
+  // The access-control rules we use here are essentially the rules for
+  // doing a lookup in Class that just magically skipped the direct
+  // members of Class itself.  That is, the naming class is Class, and the
+  // access includes the access of the base.
   for (const auto &BaseSpec : Class->bases()) {
     CXXRecordDecl *RD = cast<CXXRecordDecl>(
         BaseSpec.getType()->castAs<RecordType>()->getDecl());
     LookupResult Result(*this, R.getLookupNameInfo(), R.getLookupKind());
 	Result.setBaseObjectType(Context.getRecordType(Class));
     LookupQualifiedName(Result, RD);
-    for (auto *Decl : Result)
-      R.addDecl(Decl);
+
+    // Copy the lookup results into the target, merging the base's access into
+    // the path access.
+    for (auto I = Result.begin(), E = Result.end(); I != E; ++I) {
+      R.addDecl(I.getDecl(),
+                CXXRecordDecl::MergeAccess(BaseSpec.getAccessSpecifier(),
+                                           I.getAccess()));
+    }
+
+    Result.suppressDiagnostics();
   }
 
   R.resolveKind();
+  R.setNamingClass(Class);
 
   return !R.empty();
 }

Added: cfe/trunk/test/SemaCXX/microsoft-super.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/microsoft-super.cpp?rev=247207&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/microsoft-super.cpp (added)
+++ cfe/trunk/test/SemaCXX/microsoft-super.cpp Wed Sep  9 18:04:17 2015
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fms-extensions -verify %s
+
+// rdar://22464808
+
+namespace test0 {
+  class A {
+  private:
+    void foo(int*);
+  public:
+    void foo(long*);
+  };
+  class B : public A {
+    void test() {
+      __super::foo((long*) 0);
+    }
+  };
+}
+
+namespace test1 {
+  struct A {
+    static void foo(); // expected-note {{member is declared here}}
+  };
+  struct B : private A { // expected-note {{constrained by private inheritance here}}
+    void test() {
+      __super::foo();
+    }
+  };
+  struct C : public B {
+    void test() {
+      __super::foo(); // expected-error {{'foo' is a private member of 'test1::A'}}
+    }
+  };
+}
+
+namespace test2 {
+  struct A {
+    static void foo();
+  };
+  struct B : public A {
+    void test() {
+      __super::foo();
+    }
+  };
+  struct C : private B {
+    void test() {
+      __super::foo();
+    }
+  };
+}




More information about the cfe-commits mailing list