[llvm-branch-commits] [cfe-branch] r105041 - in /cfe/branches/Apple/whitney: lib/Sema/SemaDeclCXX.cpp test/CXX/class.access/class.friend/p1.cpp

Daniel Dunbar daniel at zuster.org
Fri May 28 16:06:57 PDT 2010


Author: ddunbar
Date: Fri May 28 18:06:57 2010
New Revision: 105041

URL: http://llvm.org/viewvc/llvm-project?rev=105041&view=rev
Log:
Merge r104917:
--
Author: John McCall <rjmccall at apple.com>
Date:   Fri May 28 01:41:47 2010 +0000

    When filtering out previous declarations of friend functions, consider the
    lookup context, not the direct semantic context.  Fixes PR7230.

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaDeclCXX.cpp
    cfe/branches/Apple/whitney/test/CXX/class.access/class.friend/p1.cpp

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaDeclCXX.cpp?rev=105041&r1=105040&r2=105041&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaDeclCXX.cpp Fri May 28 18:06:57 2010
@@ -5762,13 +5762,18 @@
 
     LookupQualifiedName(Previous, DC);
 
-    // If searching in that context implicitly found a declaration in
-    // a different context, treat it like it wasn't found at all.
+    // Ignore things found implicitly in the wrong scope.
     // TODO: better diagnostics for this case.  Suggesting the right
     // qualified scope would be nice...
-    // FIXME: getRepresentativeDecl() is not right here at all
-    if (Previous.empty() ||
-        !Previous.getRepresentativeDecl()->getDeclContext()->Equals(DC)) {
+    LookupResult::Filter F = Previous.makeFilter();
+    while (F.hasNext()) {
+      NamedDecl *D = F.next();
+      if (!D->getDeclContext()->getLookupContext()->Equals(DC))
+        F.erase();
+    }
+    F.done();
+
+    if (Previous.empty()) {
       D.setInvalidType();
       Diag(Loc, diag::err_qualified_friend_not_found) << Name << T;
       return DeclPtrTy();

Modified: cfe/branches/Apple/whitney/test/CXX/class.access/class.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/CXX/class.access/class.friend/p1.cpp?rev=105041&r1=105040&r2=105041&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/CXX/class.access/class.friend/p1.cpp (original)
+++ cfe/branches/Apple/whitney/test/CXX/class.access/class.friend/p1.cpp Fri May 28 18:06:57 2010
@@ -6,9 +6,6 @@
 //   its friends, if any, by way of friend declarations. Such declarations give
 //   special access rights to the friends, but they do not make the nominated
 //   friends members of the befriending class.
-//
-// FIXME: Add tests for access control when implemented. Currently we only test
-// for parsing.
 
 struct S { static void f(); };
 S* g() { return 0; }
@@ -287,3 +284,25 @@
     friend class test9;
   };
 }
+
+// PR7230
+namespace test10 {
+  extern "C" void f(void);
+  extern "C" void g(void);
+
+  namespace NS {
+    class C {
+      void foo(void); // expected-note {{declared private here}}
+      friend void test10::f(void);
+    };
+    static C* bar;
+  }
+
+  void f(void) {
+    NS::bar->foo();
+  }
+
+  void g(void) {
+    NS::bar->foo(); // expected-error {{private member}}
+  }
+}





More information about the llvm-branch-commits mailing list