C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Disable assignment to an rvalue

From: blacktea hamburger <greenteahamburger_at_[hidden]>
Date: Sat, 15 Oct 2022 18:42:19 +0800
I think we should choose between too much work and breaking existing code.
An easy way to allow rvalue assignment can be provided, and by default it
is not allowed.

On Saturday, October 8, 2022, Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
wrote:
> On Fri, Oct 7, 2022 at 8:21 AM blacktea hamburger via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>>
>> N2819 was rejected on the grounds that (N2920):
>>
>> N2819, "N2819 Ref-Qualifiers for assignment operators of the Standard
Library" was initially considered by the LWG. This proposal sought to
change 350 copy-assignment operators in the C++ standard library to prevent
assignment operations in which the left operand is an rvalue. Due to the
large number of changes required, the proposal was sent to EWG, with the
request that the default behavior for implicit copy-assignment operators be
reconsidered, so that assignment to an rvalue is not permitted. The EWG
resolved to maintain the status quo, because of concerns about backwards
compatibility.
>>
>> I think one reason EWG rejected it is [...]
>
> EWG said they rejected it "because of concerns about backwards
compatibility," and I believe them.
> IIUC you're proposing to take this code, valid in C++98-through-C++23,
> struct BitReference {
> void operator=(bool);
> };
> BitReference vectorFront();
> void test() {
> vectorFront() = true;
> }
> and make it give a compiler error instead. That's no good.
> –Arthur

Received on 2022-10-15 10:42:21