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 bug 5123


Hi,
this fixes bug 5123. build_component_ref couldn't cope with a template-id
as the component. This meant
	(object.foo<type>) (call,args)
broke, amongst other things.

built & tested on i686-pc-linux-gnu, ok?

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
2001-12-28  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/5123
	* typeck.c (build_component_ref): Cope with a TEMPLATE_ID_EXPR.
	(build_x_function_call): Cope with a COMPONENT_REF containing a
	TEMPLATE_ID_EXPR.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.378
diff -c -3 -p -r1.378 typeck.c
*** typeck.c	2001/12/24 20:52:36	1.378
--- typeck.c	2001/12/28 22:57:44
*************** build_component_ref (datum, component, b
*** 2038,2044 ****
  			      basetype_path, protect));
  
      case TEMPLATE_DECL:
!       error ("invalid use of %D", datum);
        datum = error_mark_node;
        break;
  
--- 2038,2044 ----
  			      basetype_path, protect));
  
      case TEMPLATE_DECL:
!       error ("invalid use of `%D'", datum);
        datum = error_mark_node;
        break;
  
*************** build_component_ref (datum, component, b
*** 2122,2128 ****
    else
      {
        tree name = component;
!       if (TREE_CODE (component) == VAR_DECL)
  	name = DECL_NAME (component);
        if (TREE_CODE (component) == NAMESPACE_DECL)
          /* Source is in error, but produce a sensible diagnostic.  */
--- 2122,2131 ----
    else
      {
        tree name = component;
!       
!       if (TREE_CODE (component) == TEMPLATE_ID_EXPR)
! 	name = TREE_OPERAND (component, 0);
!       else if (TREE_CODE (component) == VAR_DECL)
  	name = DECL_NAME (component);
        if (TREE_CODE (component) == NAMESPACE_DECL)
          /* Source is in error, but produce a sensible diagnostic.  */
*************** build_component_ref (datum, component, b
*** 2170,2177 ****
  		    }
  		}
  
  	      ref = build (COMPONENT_REF, unknown_type_node,
! 			   datum, TREE_VALUE (fndecls));
  	      return ref;
  	    }
  
--- 2173,2186 ----
  		    }
  		}
  
+ 	      fndecls = TREE_VALUE (fndecls);
+ 	      
+ 	      if (TREE_CODE (component) == TEMPLATE_ID_EXPR)
+ 		fndecls = build_nt (TEMPLATE_ID_EXPR,
+ 				    fndecls, TREE_OPERAND (component, 1));
+ 	      
  	      ref = build (COMPONENT_REF, unknown_type_node,
! 			   datum, fndecls);
  	      return ref;
  	    }
  
*************** build_x_function_call (function, params,
*** 2707,2718 ****
        /* Undo what we did in build_component_ref.  */
        decl = TREE_OPERAND (function, 0);
        function = TREE_OPERAND (function, 1);
-       function = DECL_NAME (OVL_CURRENT (function));
  
!       if (template_id)
  	{
! 	  TREE_OPERAND (template_id, 0) = function;
! 	  function = template_id;
  	}
  
        return build_method_call (decl, function, params,
--- 2716,2737 ----
        /* Undo what we did in build_component_ref.  */
        decl = TREE_OPERAND (function, 0);
        function = TREE_OPERAND (function, 1);
  
!       if (TREE_CODE (function) == TEMPLATE_ID_EXPR)
! 	{
! 	  my_friendly_assert (!template_id, 20011228);
! 
! 	  template_id = function;
! 	}
!       else
  	{
! 	  function = DECL_NAME (OVL_CURRENT (function));
! 
! 	  if (template_id)
! 	    {
! 	      TREE_OPERAND (template_id, 0) = function;
! 	      function = template_id;
! 	    }
  	}
  
        return build_method_call (decl, function, params,
// { dg-do compile }

// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@nathan@codesourcery.com>

// PR 5123. ICE

struct C {
  template<class T> void f(T);
  void g ();
  void g (int);
};

void Foo () {
  C c;

  (c.g) ();
  (c.f) (1);
  
  (c.f<int>) (2);

  c.g;			// { dg-error "statement cannot resolve" "" }
  c.f;		        // { dg-error "statement cannot resolve" "" }
  c.f<int>;		// { dg-error "statement cannot resolve" "" }
  
  c.g == 1;		// { dg-error "invalid use of" "" }
  c.f == 1;		// { dg-error "invalid use of" "" }
  c.f<int> == 1;	// { dg-error "invalid use of" "" }
};

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