C++ Logo

std-discussion

Advanced search

Re: Lvalue-to-rvalue conversion

From: F. v.S. <de34_at_[hidden]>
Date: Mon, 22 Dec 2025 07:36:06 +0000
Do you have any idea why lvalue-to-rvalue conversion on `s` would be required?

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`.


Thanks,
F.v.S.
________________________________
From: Std-Discussion <std-discussion-bounces_at_[hidden]> on behalf of Russell Shaw via Std-Discussion <std-discussion_at_[hidden]>
Sent: Monday, December 22, 2025 15:07
To: std-discussion_at_[hidden] <std-discussion_at_[hidden]>
Cc: Russell Shaw <rjshaw_at_[hidden]>
Subject: [std-discussion] Lvalue-to-rvalue conversion

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 ?]

******************************************************
--
Std-Discussion mailing list
Std-Discussion_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2025-12-22 07:36:14