C++ Logo

std-proposals

Advanced search

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

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 11 Oct 2022 19:38:14 +0300
On 10/11/22 19: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?

Because int to int is not a type conversion.

Also, presumably, in normal circumstances the function taking an rvalue
reference is not supposed to be callable with an lvalue argument. And
vise versa.

Received on 2022-10-11 16:38:33