/* In a template (or ill-formed code), we can have an incomplete type
even after require_complete_type_sfinae, in which case we don't know
whether it has trivial copy or not. */
- && COMPLETE_TYPE_P (arg_type))
+ && COMPLETE_TYPE_P (arg_type)
+ && !cp_unevaluated_operand)
{
- /* Build up a real lvalue-to-rvalue conversion in case the
- copy constructor is trivial but not callable. */
- if (!cp_unevaluated_operand && CLASS_TYPE_P (arg_type))
- force_rvalue (arg, complain);
-
/* [expr.call] 5.2.2/7:
Passing a potentially-evaluated argument of class type (Clause 9)
with a non-trivial copy constructor or a non-trivial destructor
with no corresponding parameter is conditionally-supported, with
implementation-defined semantics.
- We support it as pass-by-invisible-reference to the caller's
- object. That's different to named by-value parameters, which
- construct a copy and pass a reference to that.
+ We support it as pass-by-invisible-reference, just like a normal
+ value parameter.
If the call appears in the context of a sizeof expression,
it is not potentially-evaluated. */
- if (cp_unevaluated_operand == 0
- && (type_has_nontrivial_copy_init (arg_type)
- || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type)))
+ if (type_has_nontrivial_copy_init (arg_type)
+ || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))
{
+ arg = force_rvalue (arg, complain);
if (complain & tf_warning)
warning (OPT_Wconditionally_supported,
"passing objects of non-trivially-copyable "
arg_type);
return cp_build_addr_expr (arg, complain);
}
+ /* Build up a real lvalue-to-rvalue conversion in case the
+ copy constructor is trivial but not callable. */
+ else if (CLASS_TYPE_P (arg_type))
+ force_rvalue (arg, complain);
+
}
return arg;