re PR c++/13478 (gcc uses wrong constructor to initialize a const reference)

PR c++/13478
	* call.c (initialize_reference): Pass -1 for inner parameter to
	convert_like_real.

	PR c++/13478
	* g++.dg/init/ref10.C: New test.

From-SVN: r75983
This commit is contained in:
Mark Mitchell 2004-01-16 17:54:25 +00:00 committed by Mark Mitchell
parent a3fe7b56f3
commit 1b6bfcd2ce
2 changed files with 8 additions and 4 deletions

View File

@ -1,8 +1,8 @@
2004-01-16 Mark Mitchell <mark@codesourcery.com>
PR c++/13478
* call.c (convert_like_real): Do not perform an additional
direct-initialization when binding to a reference.
* call.c (initialize_reference): Pass -1 for inner parameter to
convert_like_real.
2004-01-15 Giovanni Bajo <giovannibajo@gcc.gnu.org>

View File

@ -4068,7 +4068,8 @@ convert_like_real (tree convs, tree expr, tree fn, int argnum, int 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) && inner >= 0)
if (IS_AGGR_TYPE (totype)
&& (inner >= 0 || !lvalue_p (expr)))
{
expr = (build_temp
(expr, totype,
@ -6250,7 +6251,10 @@ initialize_reference (tree type, tree expr, tree decl, tree *cleanup)
else
base_conv_type = NULL_TREE;
/* Perform the remainder of the conversion. */
expr = convert_like (conv, expr);
expr = convert_like_real (conv, expr,
/*fn=*/NULL_TREE, /*argnum=*/0,
/*inner=*/-1,
/*issue_conversion_warnings=*/true);
if (!real_lvalue_p (expr))
{
tree init;