C++ Logo

std-discussion

Advanced search

Lvalue-to-rvalue conversion

From: Russell Shaw <rjshaw_at_[hidden]>
Date: Mon, 22 Dec 2025 18:07:42 +1100
Hi,

In this code, what does "Lvalue-to-rvalue conversion [conv.lval]" do for "s" in
"int a = 1 + s;" ?

list.1
******************************************************
struct S {
   operator int() {
     return 0;
   }
};

S s;

int a = 1 + s;
******************************************************


I assume the code is converted to:

list.2
******************************************************
struct S {
   operator int() {
     return 0;
   }
};

S s;

int tmp = s.operator int();

int a = 1 + tmp;
******************************************************


How are these rules used in list.1 ? :

******************************************************
The result of the conversion is determined according to the following rules:

...

— Otherwise, if T has a class type, the conversion copy-initializes the result
object from the glvalue. ?????????????

...
— Otherwise, the object indicated by the glvalue is read (3.1), and the value
contained in the object is the prvalue result.

[is this invoking the conversion function ?]

******************************************************

Received on 2025-12-22 07:07:49