- expr = build_typed_address (expr, type);
- return convert_from_reference (expr);
+ /* Handle the lvalue case here by casting to lvalue reference and
+ then changing it to an rvalue reference. Casting an xvalue to
+ rvalue reference will be handled by the main code path. */
+ tree lref = cp_build_reference_type (TREE_TYPE (type), false);
+ result = (perform_direct_initialization_if_possible
+ (lref, expr, c_cast_p, complain));
+ result = cp_fold_convert (type, result);
+ /* Make sure we don't fold back down to a named rvalue reference,
+ because that would be an lvalue. */
+ if (DECL_P (result))
+ result = build1 (NON_LVALUE_EXPR, type, result);
+ return convert_from_reference (result);