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]: DR 209 is not a defect


Hi,
Jason has pointed out that DR209 is no more
(http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#209)
I generated a patch to implement the original proposal (well, almost,
but as you'll see from the DR, it's a little ill-defined).

This patch reverts the implementation of DR209, but leaves in the
other parts of that patch (see PR c++/2137). We still do not check the
access of the friend function.

built & tested on i686-pc-linux-gnu, ok for mainline?
(This is not a regression, as we only started doing type access control
in 3.0, which that patch turned off in this case.)

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-03-03  Nathan Sidwell  <nathan@codesourcery.com>

	Revert 2001-03-26  Nathan Sidwell  <nathan@codesourcery.com>,
	DR209 is now not a defect.
	* cp-tree.h (skip_type_access_control): Remove.
	* decl.c (grokdeclarator): Do type access control for friend
	declarations.
	* semantics.c (decl_type_access_control): Don't reset
	current_type_lookups.
	(save_type_access_control): Always save the lookups.
	(skip_type_access_control): Remove.
	(finish_class_definition): Don't change type_lookups.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.683
diff -c -3 -p -r1.683 cp-tree.h
*** cp-tree.h	2002/03/01 07:19:29	1.683
--- cp-tree.h	2002/03/03 21:48:22
*************** extern int types_overlap_p			PARAMS ((tr
*** 4062,4069 ****
  extern tree get_vbase				PARAMS ((tree, tree));
  extern tree get_dynamic_cast_base_type          PARAMS ((tree, tree));
  extern void type_access_control			PARAMS ((tree, tree));
- extern void skip_type_access_control            PARAMS ((void));
- extern void reset_type_access_control           PARAMS ((void));
  extern int accessible_p                         PARAMS ((tree, tree));
  extern tree lookup_field			PARAMS ((tree, tree, int, int));
  extern int lookup_fnfields_1                    PARAMS ((tree, tree));
--- 4062,4067 ----
*************** extern tree finish_qualified_call_expr  
*** 4171,4176 ****
--- 4169,4175 ----
  extern tree finish_unary_op_expr                PARAMS ((enum tree_code, tree));
  extern tree finish_id_expr                      PARAMS ((tree));
  extern void save_type_access_control		PARAMS ((tree));
+ extern void reset_type_access_control           PARAMS ((void));
  extern void decl_type_access_control		PARAMS ((tree));
  extern int begin_function_definition            PARAMS ((tree, tree));
  extern tree begin_constructor_declarator        PARAMS ((tree, tree));
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.868
diff -c -3 -p -r1.868 decl.c
*** decl.c	2002/03/02 19:51:55	1.868
--- decl.c	2002/03/03 21:48:55
*************** friend declaration requires class-key, i
*** 11293,11301 ****
  	  /* Only try to do this stuff if we didn't already give up.  */
  	  if (type != integer_type_node)
  	    {
! 	      /* DR 209. The friendly class does not need to be accessible
!                  in the scope of the class granting friendship. */
! 	      skip_type_access_control ();
  
  	      /* A friendly class?  */
  	      if (current_class_type)
--- 11293,11299 ----
  	  /* Only try to do this stuff if we didn't already give up.  */
  	  if (type != integer_type_node)
  	    {
! 	      decl_type_access_control (TYPE_NAME (type));
  
  	      /* A friendly class?  */
  	      if (current_class_type)
*************** friend declaration requires class-key, i
*** 11557,11589 ****
  	if (friendp)
  	  {
  	    /* Friends are treated specially.  */
-             tree t = NULL_TREE;
- 	    
- 	    /* DR 209. The friend does not need to be accessible at this
-                point. */
- 	    skip_type_access_control ();
- 	    
  	    if (ctype == current_class_type)
  	      warning ("member functions are implicitly friends of their class");
! 
!             if (decl && DECL_NAME (decl))
!               {
!                 if (template_class_depth (current_class_type) == 0)
!                   {
!               	    decl = check_explicit_specialization
!               	            (declarator, decl,
!               	             template_count, 2 * (funcdef_flag != 0) + 4);
!               	    if (decl == error_mark_node)
!               	      return error_mark_node;
!                   }
!               
!                 t = do_friend (ctype, declarator, decl,
!               		       last_function_parms, *attrlist, flags, quals,
!               		       funcdef_flag);
!               }
!             if (t && funcdef_flag)
!               return t;
! 	    return void_type_node;
  	  }
  
  	/* Structure field.  It may not be a function, except for C++ */
--- 11555,11586 ----
  	if (friendp)
  	  {
  	    /* Friends are treated specially.  */
  	    if (ctype == current_class_type)
  	      warning ("member functions are implicitly friends of their class");
!  	    else
!  	      {
!  		tree t = NULL_TREE;
!  		if (decl && DECL_NAME (decl))
!  		  {
!  		    if (template_class_depth (current_class_type) == 0)
!  		      {
!  			decl
!  			  = check_explicit_specialization
!  			  (declarator, decl,
!  			   template_count, 2 * (funcdef_flag != 0) + 4);
!  			if (decl == error_mark_node)
!  			  return error_mark_node;
!  		      }
! 		    
!  		    t = do_friend (ctype, declarator, decl,
!  				   last_function_parms, *attrlist,
! 				   flags, quals, funcdef_flag);
!  		  }
!  		if (t && funcdef_flag)
!  		  return t;
!   
!  		return void_type_node;
!  	      }
  	  }
  
  	/* Structure field.  It may not be a function, except for C++ */
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.252
diff -c -3 -p -r1.252 semantics.c
*** semantics.c	2002/02/22 17:42:19	1.252
--- semantics.c	2002/03/03 21:49:09
*************** decl_type_access_control (decl)
*** 1502,1533 ****
       added to type_lookups after typed_declspecs saved the copy that
       ended up in current_type_lookups.  */
    type_lookups = current_type_lookups;
-   
-   current_type_lookups = NULL_TREE;
  }
  
- /* Record the lookups, if we're doing deferred access control.  */
- 
  void
  save_type_access_control (lookups)
       tree lookups;
- {
-   if (type_lookups != error_mark_node)
-     {
-       my_friendly_assert (!current_type_lookups, 20010301);
-       current_type_lookups = lookups;
-     }
-   else
-     my_friendly_assert (!lookups || lookups == error_mark_node, 20010301);
- }
- 
- /* Set things up so that the next deferred access control will succeed.
-    This is needed for friend declarations see grokdeclarator for details.  */
- 
- void
- skip_type_access_control ()
  {
!   type_lookups = NULL_TREE;
  }
  
  /* Reset the deferred access control.  */
--- 1502,1514 ----
       added to type_lookups after typed_declspecs saved the copy that
       ended up in current_type_lookups.  */
    type_lookups = current_type_lookups;
  }
  
  void
  save_type_access_control (lookups)
       tree lookups;
  {
!   current_type_lookups = lookups;
  }
  
  /* Reset the deferred access control.  */
*************** finish_class_definition (t, attributes, 
*** 1911,1918 ****
      check_for_missing_semicolon (t); 
    if (pop_scope_p)
      pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
-   if (current_function_decl)
-     type_lookups = error_mark_node;
    if (current_scope () == current_function_decl)
      do_pending_defargs ();
  
--- 1892,1897 ----

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