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]

[C++ PATCH] Fix bug 2117


Hi,
i've installed the attached on both mainline and 3.0 branch to fix
bug 2117. We were erroneously creating a temporary when we'd
called a conversion function which returned a reference, before
binding to a reference parameter.

built & tested on i686-pc-linux-gnu, approved by Mark

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-02-27  Nathan Sidwell  <nathan@codesourcery.com>

	* call.c (convert_like_real): Add extra semantics to INNER
	parameter. Don't convert to temporary if a user conversion
	gives us an lvalue that we're about to bind to a reference.
	Set INNER to indicate pending reference binding on recursive
	calls.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.262
diff -c -3 -p -r1.262 call.c
*** call.c	2001/02/26 15:59:30	1.262
--- call.c	2001/02/27 16:09:45
*************** enforce_access (basetype_path, decl)
*** 3676,3682 ****
  /* Perform the conversions in CONVS on the expression EXPR. 
     FN and ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
     indicates the `this' argument of a method.  INNER is non-zero when
!    being called to continue a conversion chain. */
  
  static tree
  convert_like_real (convs, expr, fn, argnum, inner)
--- 3676,3683 ----
  /* Perform the conversions in CONVS on the expression EXPR. 
     FN and ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
     indicates the `this' argument of a method.  INNER is non-zero when
!    being called to continue a conversion chain. It is negative when a
!    reference binding will be applied, positive otherwise. */
  
  static tree
  convert_like_real (convs, expr, fn, argnum, inner)
*************** convert_like_real (convs, expr, fn, argn
*** 3755,3761 ****
  	   conversion, but is not considered during overload resolution.
  
  	   If the target is a class, that means call a ctor.  */
! 	if (IS_AGGR_TYPE (totype))
  	  {
  	    savew = warningcount, savee = errorcount;
  	    expr = build_new_method_call
--- 3756,3763 ----
  	   conversion, but is not considered during overload resolution.
  
  	   If the target is a class, that means call a ctor.  */
! 	if (IS_AGGR_TYPE (totype)
! 	    && (inner >= 0 || !real_lvalue_p (expr)))
  	  {
  	    savew = warningcount, savee = errorcount;
  	    expr = build_new_method_call
*************** convert_like_real (convs, expr, fn, argn
*** 3804,3810 ****
        break;
      };
  
!   expr = convert_like_real (TREE_OPERAND (convs, 0), expr, fn, argnum, 1);
    if (expr == error_mark_node)
      return error_mark_node;
  
--- 3806,3813 ----
        break;
      };
  
!   expr = convert_like_real (TREE_OPERAND (convs, 0), expr, fn, argnum,
!                             TREE_CODE (convs) == REF_BIND ? -1 : 1);
    if (expr == error_mark_node)
      return error_mark_node;
  
// Build don't link:

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

// Bug 2117. A conversion op to reference type created a temporary, even
// when bound to another reference.

struct Abstract
{
  virtual void Foo () = 0;
};

struct Proxy
{
  operator Abstract & ();
  Abstract &Convert ();
};

void Baz (Abstract &);

void Foo ()
{
  Proxy proxy;
  
  Baz (proxy);
  Baz (proxy.Convert ());
}

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