]> granicus.if.org Git - clang/commitdiff
The effective context of a friend function is its lexical
authorDouglas Gregor <dgregor@apple.com>
Sun, 9 Oct 2011 22:38:36 +0000 (22:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 9 Oct 2011 22:38:36 +0000 (22:38 +0000)
context. Fixes PR9103.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141520 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaAccess.cpp
test/CXX/class.access/class.friend/p1.cpp
test/CXX/class.access/class.protected/p1.cpp

index 14c8ebafe7d24c668021f6e7623bc26e92234e1c..d322ebd410078f12f1149a7baefc71a1fae9c056 100644 (file)
@@ -103,7 +103,11 @@ struct EffectiveContext {
       } else if (isa<FunctionDecl>(DC)) {
         FunctionDecl *Function = cast<FunctionDecl>(DC)->getCanonicalDecl();
         Functions.push_back(Function);
-        DC = Function->getDeclContext();
+        
+        if (Function->getFriendObjectKind())
+          DC = Function->getLexicalDeclContext();
+        else
+          DC = Function->getDeclContext();
       } else if (DC->isFileContext()) {
         break;
       } else {
index 1668155c18196a30248c3b7cef3b767d20aa4412..68ff83fee83c453cd26608474668e024e5a2ad32 100644 (file)
@@ -341,3 +341,16 @@ namespace test12 {
     void *var = static_cast<B*>(this)->mem;
   }
 }
+
+namespace PR9103 {
+  struct base {
+  protected:
+    static void foo(void) {}
+  };
+
+  struct cls: base {
+    friend void bar(void) {
+      base::foo();
+    }
+  };
+}
index 8698fb1da8a56ff07344793e2acfd17fd2761a8d..79bb6cd67eab805400919eaa1b104e39619874c8 100644 (file)
@@ -423,7 +423,7 @@ namespace test12 {
 // This friendship is not considered because a public member of A is
 // inaccessible in C.
 namespace test13 {
-  class A { protected: int foo(); }; // expected-note {{declared protected here}}
+  class A { protected: int foo(); }; // expected-note {{object type 'test13::D' must derive from context type 'test13::C'}}
   class B : private virtual A {};
   class C : private B { friend void test(); };
   class D : public virtual A {};