PATCH for pointers-to-members/templates

Mark Mitchell mark@markmitchell.com
Wed May 27 20:00:00 GMT 1998


Niall --

  Here's a patch that allows the formation of pointers-to-members for
member templates using the <> syntax.  Jason, OK?

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-05-27  Mark Mitchell  <mark@markmitchell.com>

	* class.c (instantiate_type): Handle pointer-to-members where the
	member is a template.
	* init.c (build_offset_ref): Likewise.
	* typeck.c (build_unary_op): Likewise.
	
Index: ptrmem1.C
===================================================================
RCS file: ptrmem1.C
diff -N ptrmem1.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- ptrmem1.C	Wed May 27 19:15:42 1998
***************
*** 0 ****
--- 1,16 ----
+ // Build don't run:
+ 
+ class foo
+ {
+ public:
+   template<class T>
+   T bar() {}
+ };
+ 
+ int
+ main()
+ {
+   foo f;
+   
+   int (foo::*s)() = &foo::template bar<int>;
+ }
Index: class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.56
diff -c -p -r1.56 class.c
*** class.c	1998/05/26 11:43:42	1.56
--- class.c	1998/05/28 02:12:01
*************** instantiate_type (lhstype, rhs, complain
*** 5091,5096 ****
--- 5091,5111 ----
  	return rhs;
        }
  
+     case SCOPE_REF:
+       {
+ 	/* This can happen if we are forming a pointer-to-member for a
+ 	   member template.  */
+ 	tree template_id_expr = TREE_OPERAND (rhs, 1);
+ 	tree name;
+ 	my_friendly_assert (TREE_CODE (template_id_expr) == TEMPLATE_ID_EXPR,
+ 			    0);
+ 	explicit_targs = TREE_OPERAND (template_id_expr, 1);
+ 	name = TREE_OPERAND (template_id_expr, 0);
+ 	my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 0);
+ 	rhs = lookup_fnfields (TYPE_BINFO (TREE_OPERAND (rhs, 0)), name, 1);
+ 	goto overload;
+       }
+ 
      case TEMPLATE_ID_EXPR:
        {
  	explicit_targs = TREE_OPERAND (rhs, 1);
*************** instantiate_type (lhstype, rhs, complain
*** 5100,5105 ****
--- 5115,5121 ----
        my_friendly_assert (TREE_CODE (rhs) == OVERLOAD, 980401);
  
      case OVERLOAD:
+     overload:
        {
  	tree elem, elems;
  
*************** instantiate_type (lhstype, rhs, complain
*** 5111,5117 ****
  	if (lhstype == error_mark_node)
  	  return lhstype;
  
! 	if (TREE_CODE (lhstype) != FUNCTION_TYPE)
  	  {
  	    rhs = DECL_NAME (OVL_FUNCTION (rhs));
  	    if (complain)
--- 5127,5134 ----
  	if (lhstype == error_mark_node)
  	  return lhstype;
  
! 	if (TREE_CODE (lhstype) != FUNCTION_TYPE
! 	    && TREE_CODE (lhstype) != METHOD_TYPE)
  	  {
  	    rhs = DECL_NAME (OVL_FUNCTION (rhs));
  	    if (complain)
Index: init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.40
diff -c -p -r1.40 init.c
*** init.c	1998/05/25 10:28:11	1.40
--- init.c	1998/05/28 02:12:12
*************** build_offset_ref (type, name)
*** 1615,1628 ****
    int dtor = 0;
  
    /* class templates can come in as TEMPLATE_DECLs here.  */
!   if (TREE_CODE (name) != IDENTIFIER_NODE)
      return name;
  
    if (type == std_node)
      return do_scoped_id (name, 0);
  
!   if (processing_template_decl || uses_template_parms (type))
!     return build_min_nt (SCOPE_REF, type, name);
  
    /* Handle namespace names fully here.  */
    if (TREE_CODE (type) == NAMESPACE_DECL)
--- 1615,1629 ----
    int dtor = 0;
  
    /* class templates can come in as TEMPLATE_DECLs here.  */
!   if (TREE_CODE (name) == TEMPLATE_DECL)
      return name;
  
    if (type == std_node)
      return do_scoped_id (name, 0);
  
!   if (processing_template_decl || uses_template_parms (type)
!       || TREE_CODE (name) == TEMPLATE_ID_EXPR)
!     return build_min (SCOPE_REF, unknown_type_node, type, name);
  
    /* Handle namespace names fully here.  */
    if (TREE_CODE (type) == NAMESPACE_DECL)
Index: typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.74
diff -c -p -r1.74 typeck.c
*** typeck.c	1998/05/25 10:28:15	1.74
--- typeck.c	1998/05/28 02:12:39
*************** build_unary_op (code, xarg, noconvert)
*** 4558,4564 ****
  	  return build1 (ADDR_EXPR, unknown_type_node, arg);
  	}
  
!       if (TREE_CODE (arg) == OVERLOAD)
  	return build1 (ADDR_EXPR, unknown_type_node, arg);
        else if (TREE_CODE (arg) == TREE_LIST)
  	{
--- 4558,4566 ----
  	  return build1 (ADDR_EXPR, unknown_type_node, arg);
  	}
  
!       if (TREE_CODE (arg) == OVERLOAD 
! 	  || (TREE_CODE (arg) == SCOPE_REF 
! 	      && TREE_CODE (TREE_OPERAND (arg, 1)) == TEMPLATE_ID_EXPR))
  	return build1 (ADDR_EXPR, unknown_type_node, arg);
        else if (TREE_CODE (arg) == TREE_LIST)
  	{



More information about the Gcc-patches mailing list