C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Specify that argument to function cannot be an rvalue

From: Bo Persson <bo_at_[hidden]>
Date: Tue, 11 Oct 2022 18:13:14 +0200
On 2022-10-11 at 18:08, Thiago Macieira via Std-Proposals wrote:
> On Tuesday, 11 October 2022 04:30:52 PDT Ville Voutilainen via Std-Proposals
> wrote:
>> void f(int&&) { puts("int"); }
>> void f(double&&) { puts("double"); }
>>
>> so
>>
>> int i = 1;
>> f(i);
>>
>> prints "double", because it can't call void f(int&&). Instead, it'll
>> convert the int to double,
>> and call void f(double&&).
>
> But why can't it convert int to int and then call the int&& overload?
>

That's just not one of the conversions that happens. You would need a
std::move(i) for that.

Received on 2022-10-11 16:13:22