[cfe-commits] r101706 - in /cfe/trunk: lib/Sema/SemaAccess.cpp test/CXX/class.access/class.friend/p1.cpp

Chandler Carruth chandlerc at gmail.com
Sun Apr 18 01:23:21 PDT 2010


Author: chandlerc
Date: Sun Apr 18 03:23:21 2010
New Revision: 101706

URL: http://llvm.org/viewvc/llvm-project?rev=101706&view=rev
Log:
Fix the access checking of function and function template argument types,
return types, and default arguments. This fixes PR6855 along with several
similar cases where we rejected valid code.

Modified:
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/test/CXX/class.access/class.friend/p1.cpp

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=101706&r1=101705&r2=101706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Sun Apr 18 03:23:21 2010
@@ -1015,8 +1015,15 @@
 
 void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *Ctx) {
   // Pretend we did this from the context of the newly-parsed
-  // declaration.
-  EffectiveContext EC(Ctx->getDeclContext());
+  // declaration. If that declaration itself forms a declaration context,
+  // include it in the effective context so that parameters and return types of
+  // befriended functions have that function's access priveledges.
+  DeclContext *DC = Ctx->getDeclContext();
+  if (isa<FunctionDecl>(Ctx))
+    DC = cast<DeclContext>(Ctx);
+  else if (FunctionTemplateDecl *FnTpl = dyn_cast<FunctionTemplateDecl>(Ctx))
+    DC = cast<DeclContext>(FnTpl->getTemplatedDecl());
+  EffectiveContext EC(DC);
 
   AccessTarget Target(DD.getAccessData());
 

Modified: cfe/trunk/test/CXX/class.access/class.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/class.friend/p1.cpp?rev=101706&r1=101705&r2=101706&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/class.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/class.access/class.friend/p1.cpp Sun Apr 18 03:23:21 2010
@@ -256,3 +256,27 @@
     A a; // expected-error {{calling a private constructor}}
   }
 }
+
+// Return types, parameters and default arguments to friend functions.
+namespace test8 {
+  class A {
+    typedef int I; // expected-note 4 {{declared private here}}
+    static const I x = 0;
+    friend I f(I i);
+    template<typename T> friend I g(I i);
+  };
+
+  // FIXME: This should be on line 264.
+  const A::I A::x; // expected-note {{declared private here}}
+  A::I f(A::I i = A::x) {}
+  template<typename T> A::I g(A::I i) {
+    T t;
+  }
+  template A::I g<A::I>(A::I i);
+
+  A::I f2(A::I i = A::x) {} // expected-error 3 {{is a private member of}}
+  template<typename T> A::I g2(A::I i) { // expected-error 2 {{is a private member of}}
+    T t;
+  }
+  template A::I g2<A::I>(A::I i);
+}





More information about the cfe-commits mailing list