C++ Logo

std-discussion

Advanced search

Re: Deleting the Rvalue member function

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 30 Dec 2022 10:24:18 -0500
On Fri, Dec 30, 2022 at 8:28 AM Frederick Virchanza Gotham via
Std-Discussion <std-discussion_at_[hidden]> wrote:
>
>
>
> On Friday, December 30, 2022, Lénárd Szolnoki via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>
>> >Do you reckon it should be a compiler error to delete the unary '&'
>> >operator for Rvalues? Should I post to the proposals group to make it a
>> >compiler error in C++26?
>>
>> What would be the reasoning? I mean not many operator& overloads make sense, including a deleted rvalue one, but I don't see a reason to needlessly introduce a corner case to the language.
>
>
>
> Does it make sense to be able to 'delete' something that isn't automatically provided? You can't apply & to an Rvalue anyway.

Yes. This is usually done to prevent certain implicit conversions:

```
void func(int);
void func(float) = delete;
```

If you try to call `func(0.5f)`, you will get a compile error. The
same goes if you try to pass a double. Those match `float` better than
`int`, so overload resolution will pick them.

`= delete` as applied to an rvalue `this` overload would be done to
prevent someone from calling that function with an rvalue.

Received on 2022-12-30 15:24:31