re PR c++/13478 (gcc uses wrong constructor to initialize a const reference)
authorMark Mitchell <mark@codesourcery.com>
Fri, 16 Jan 2004 17:54:25 +0000 (17:54 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 16 Jan 2004 17:54:25 +0000 (17:54 +0000)
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

gcc/cp/ChangeLog
gcc/cp/call.c

index 3c41c9a2585d486b401fda84c50b9896b6d018c8..c2458abfe86d020353e1f218dc4463ae9db9b1a1 100644 (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>
 
index 74878fd5cdc66786bd34b887a301cdb54b213e0d..aaf902ceed63ff8422624f595b831cfe9dbdd703 100644 (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;