flags);
if (cand)
- cand->second_conv = build_identity_conv (totype, NULL_TREE);
+ {
+ cand->second_conv = build_identity_conv (totype, NULL_TREE);
+
+ /* If totype isn't a reference, and LOOKUP_NO_TEMP_BIND isn't
+ set, then this is copy-initialization. In that case, "The
+ result of the call is then used to direct-initialize the
+ object that is the destination of the copy-initialization."
+ [dcl.init]
+
+ We represent this in the conversion sequence with an
+ rvalue conversion, which means a constructor call. */
+ if (TREE_CODE (totype) != REFERENCE_TYPE
+ && !(convflags & LOOKUP_NO_TEMP_BIND))
+ cand->second_conv
+ = build_conv (ck_rvalue, totype, cand->second_conv);
+ }
}
if (conv_fns)
0,
/*c_cast_p=*/false, convflags);
+ /* If LOOKUP_NO_TEMP_BIND isn't set, then this is
+ copy-initialization. In that case, "The result of the
+ call is then used to direct-initialize the object that is
+ the destination of the copy-initialization." [dcl.init]
+
+ We represent this in the conversion sequence with an
+ rvalue conversion, which means a constructor call. But
+ don't add a second rvalue conversion if there's already
+ one there. Which there really shouldn't be, but it's
+ harmless since we'd add it here anyway. */
+ if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
+ && !(convflags & LOOKUP_NO_TEMP_BIND))
+ ics = build_conv (ck_rvalue, totype, ics);
+
cand->second_conv = ics;
if (!ics)
if (DECL_CONSTRUCTOR_P (convfn))
expr = build_cplus_new (totype, expr);
- /* The result of the call is then used to direct-initialize the object
- that is the destination of the copy-initialization. [dcl.init]
-
- Note that this step is not reflected in the conversion sequence;
- it affects the semantics when we actually perform the
- conversion, but is not considered during overload resolution.
-
- If the target is a class, that means call a ctor. */
- if (MAYBE_CLASS_TYPE_P (totype)
- && (inner >= 0 || !lvalue_p (expr)))
- {
- expr = (build_temp
- (expr, totype,
- /* Core issue 84, now a DR, says that we don't
- allow UDCs for these args (which deliberately
- breaks copy-init of an auto_ptr<Base> from an
- auto_ptr<Derived>). */
- LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION,
- &diagnostic_fn));
-
- if (diagnostic_fn && (complain & tf_error))
- {
- if (fn)
- diagnostic_fn
- (" initializing argument %P of %qD from result of %qD",
- argnum, fn, convfn);
- else
- diagnostic_fn
- (" initializing temporary from result of %qD", convfn);
- }
- expr = build_cplus_new (totype, expr);
- }
return expr;
}
case ck_identity:
flags = LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING;
if (convs->user_conv_p)
/* This conversion is being done in the context of a user-defined
- conversion, so don't allow any more. */
+ conversion (i.e. the second step of copy-initialization), so
+ don't allow any more. */
flags |= LOOKUP_NO_CONVERSION;
expr = build_temp (expr, totype, flags, &diagnostic_fn);
if (diagnostic_fn && fn)