C++ Logo

std-proposals

Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 7 Oct 2022 18:46:49 -0400
On Fri, Oct 7, 2022 at 8:21 AM blacktea hamburger via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> N2819 <https://wg21.link/N2819> was rejected on the grounds that (N2920
> <https://wg21.link/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-07 22:47:01