This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix PR7809 (access checking in friend declaration)


Hi

I would be away for a few weeks.  I decide post a bunch of finished
patches here so that there are plenty of time to review.  I will
apply the approved ones when I am back early July.  Here is the
first one.

This patch fixes PR 7809, we never check that the declared friend is
accessible.  This patch adds a check when the friend (ordinary
function or template) is a member function.

Tested on i686-pc-linux-gnu.  OK for trunk?

--Kriang



2003-06-16  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/7809
	* friend.c (add_friend): Check access for member functions
	and templates.

2003-06-16  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/7809
	* g++.dg/parse/access3.C: New test.


diff -cprN gcc-main-save/gcc/cp/friend.c gcc-main-new/gcc/cp/friend.c
*** gcc-main-save/gcc/cp/friend.c	Sun Jun  8 00:07:59 2003
--- gcc-main-new/gcc/cp/friend.c	Sun Jun  8 00:55:16 2003
*************** add_friend (type, decl)
*** 172,177 ****
--- 172,180 ----
        list = TREE_CHAIN (list);
      }
  
+   if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
+     perform_or_defer_access_check (DECL_CONTEXT (decl), decl);
+ 
    maybe_add_class_template_decl_list (type, decl, /*friend_p=*/1);
  
    DECL_FRIENDLIST (typedecl)
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/parse/access3.C gcc-main-new/gcc/testsuite/g++.dg/parse/access3.C
*** gcc-main-save/gcc/testsuite/g++.dg/parse/access3.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/parse/access3.C	Sun Jun  8 01:19:06 2003
***************
*** 0 ****
--- 1,14 ----
+ // { dg-do compile }
+ 
+ // Origin: <bagnara@cs.unipr.it>
+ 
+ // PR c++/7809: Befriending inaccessible name.
+ 
+ class A {
+ private:
+   void f();		// { dg-error "private" }
+ };
+ 
+ class B {
+   friend void A::f();	// { dg-error "context" }
+ };


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]