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 friend19.C regression


This patch fixes the problem friend19.C -- we must not check
accessibility while processing the body of a template.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-07-09  Mark Mitchell  <mark@codesourcery.com>

	* parser.c (cp_parser_primary_expression): Preserve the form of
	qualified expressions in templates, even if they are not
	dependent.
	* pt.c (convert_nontype_argument): Handle non-dependent SCOPE_REFs.
	(tsubst_qualified_id): Likewise.
	* search.c (accessible_p): Treat everything in the body of a

Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.77
diff -c -5 -p -r1.77 parser.c
*** parser.c	9 Jul 2003 08:48:00 -0000	1.77
--- parser.c	9 Jul 2003 20:21:22 -0000
*************** cp_parser_primary_expression (cp_parser 
*** 2646,2655 ****
--- 2646,2661 ----
  		    if (TYPE_P (parser->scope)
  			&& dependent_type_p (parser->scope))
  		      return build_nt (SCOPE_REF, 
  				       parser->scope, 
  				       id_expression);
+ 		    else if (TYPE_P (parser->scope)
+ 			     && DECL_P (decl))
+ 		      return build (SCOPE_REF,
+ 				    TREE_TYPE (decl),
+ 				    parser->scope,
+ 				    id_expression);
  		    else
  		      return decl;
  		  }
  		/* A TEMPLATE_ID already contains all the information
  		   we need.  */
*************** cp_parser_primary_expression (cp_parser 
*** 2703,2712 ****
--- 2709,2723 ----
  			(decl, parser->scope, current_class_type));
  		if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
  		  *qualifying_class = parser->scope;
  		else if (!processing_template_decl)
  		  decl = convert_from_reference (decl);
+ 		else if (TYPE_P (parser->scope))
+ 		  decl = build (SCOPE_REF,
+ 				TREE_TYPE (decl),
+ 				parser->scope,
+ 				decl);
  	      }
  	    else
  	      /* Transform references to non-static data members into
  		 COMPONENT_REFs.  */
  	      decl = hack_identifier (decl, id_expression);
Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.717
diff -c -5 -p -r1.717 pt.c
*** pt.c	9 Jul 2003 08:48:00 -0000	1.717
--- pt.c	9 Jul 2003 20:21:23 -0000
*************** convert_nontype_argument (tree type, tre
*** 3052,3062 ****
      {
        if (TREE_CODE (expr) != PTRMEM_CST)
  	goto bad_argument;
      }
    else if (TYPE_PTR_P (expr_type)
- 	   || TYPE_PTRMEM_P (expr_type)
  	   || TREE_CODE (expr_type) == ARRAY_TYPE
  	   || TREE_CODE (type) == REFERENCE_TYPE
  	   /* If expr is the address of an overloaded function, we
  	      will get the unknown_type_node at this point.  */
  	   || expr_type == unknown_type_node)
--- 3052,3061 ----
*************** convert_nontype_argument (tree type, tre
*** 3098,3107 ****
--- 3097,3109 ----
  	  error ("string literal %E is not a valid template argument because it is the address of an object with static linkage", 
  		    referent);
  	  return NULL_TREE;
  	}
  
+       if (TREE_CODE (referent) == SCOPE_REF)
+ 	referent = TREE_OPERAND (referent, 1);
+ 
        if (is_overloaded_fn (referent))
  	/* We'll check that it has external linkage later.  */
  	;
        else if (TREE_CODE (referent) != VAR_DECL)
  	goto bad_argument;
*************** tsubst_qualified_id (tree qualified_id, 
*** 7158,7175 ****
        is_template = false;
        template_args = NULL_TREE;
      }
  
    expr = tsubst_copy (name, args, complain, in_decl);
!   if (!BASELINK_P (name))
!     {
!       expr = lookup_qualified_name (scope, expr, /*is_type_p=*/0);
!       if (DECL_P (expr))
! 	check_accessibility_of_qualified_id (expr, 
! 					     /*object_type=*/NULL_TREE,
! 					     scope);
!     }
  
    /* Remember that there was a reference to this entity.  */
    if (DECL_P (expr))
      mark_used (expr);
  
--- 7160,7176 ----
        is_template = false;
        template_args = NULL_TREE;
      }
  
    expr = tsubst_copy (name, args, complain, in_decl);
!   if (!BASELINK_P (name)
!       && !DECL_P (expr))
!     expr = lookup_qualified_name (scope, expr, /*is_type_p=*/0);
!   if (DECL_P (expr))
!     check_accessibility_of_qualified_id (expr, 
! 					 /*object_type=*/NULL_TREE,
! 					 scope);
  
    /* Remember that there was a reference to this entity.  */
    if (DECL_P (expr))
      mark_used (expr);
  
Index: search.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/search.c,v
retrieving revision 1.273
diff -c -5 -p -r1.273 search.c
*** search.c	8 Jul 2003 01:38:44 -0000	1.273
--- search.c	9 Jul 2003 20:21:23 -0000
*************** accessible_p (tree type, tree decl)
*** 901,910 ****
--- 901,917 ----
    /* If this declaration is in a block or namespace scope, there's no
       access control.  */
    if (!TYPE_P (context_for_name_lookup (decl)))
      return 1;
  
+   /* In a template declaration, we cannot be sure whether the
+      particular specialization that is instantiated will be a friend
+      or not.  Therefore, all access checks are deferred until
+      instantiation.  */
+   if (processing_template_decl)
+     return 1;
+ 
    if (!TYPE_P (type))
      {
        binfo = type;
        type = BINFO_TYPE (type);
      }


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