+2001-03-12 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.
+
2001-03-10 Neil Booth <neil@daikokuya.demon.co.uk>
* cp/lex.c: Delete duplicate pending_lang_change.
/* 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. */
+ 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)
conversion, but is not considered during overload resolution.
If the target is a class, that means call a ctor. */
- if (IS_AGGR_TYPE (totype))
+ if (IS_AGGR_TYPE (totype)
+ && (inner >= 0 || !real_lvalue_p (expr)))
{
savew = warningcount, savee = errorcount;
expr = build_new_method_call
break;
};
- expr = convert_like_real (TREE_OPERAND (convs, 0), expr, fn, argnum, 1);
+ 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;
--- /dev/null
+// 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 ());
+}