C++ Logo

std-discussion

Advanced search

Re: Lvalue-to-rvalue conversion

From: Russell Shaw <rjshaw_at_[hidden]>
Date: Mon, 22 Dec 2025 19:20:33 +1100
On 22/12/25 18:36, F. v.S. via Std-Discussion wrote:
> Do you have any idea why lvalue-to-rvalue conversion on `s` would be required?

It says in [conv.general]:

******************************************************
A standard conversion sequence will be applied to an expression if necessary to
convert it to a required destination type.

note 2 Expressions with a given type will be implicitly converted to other types
in several contexts:

— When used as operands of operators. The operator’s requirements for its
operands dictate the destination type (7.6).
...
******************************************************

> I think in this case, the built-in candidate of operator+ requires two `int`
> prvalues to be operands, which doesn't trigger lvalue-to-rvalue conversion on `s`.

If it requires prvalue operands, this must be done from [basic.lval]:

******************************************************
Whenever a glvalue appears as an operand of an operator that expects a prvalue
for that operand, the lvalue-to-rvalue (7.3.2), array-to-pointer (7.3.3), or
function-to-pointer (7.3.4) standard conversions are applied
to convert the expression to a prvalue.
******************************************************

This is the first step of a standard conversion sequence.

> Thanks,
> F.v.S.

Received on 2025-12-22 08:20:38