C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Enforce const correctness on deleted move constructor

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sat, 2 Dec 2023 23:00:46 +0100
On 02/12/2023 21.46, Smith, Jim via Std-Proposals wrote:
> Hi,
>
> Example:
> class A {
> public:
> ...
> A(const A&&) = delete ;
> ...
> };
>
> The above deleted move constructor with const signature should not delete the default move constructor with non-const signature A(A&&) as the compiler error says for the following code:
>
> A x;
> A a = std::move(x);
>
> *compiler: *note: 'A' has been explicitly marked deleted here
> A(const A&&) = delete;
>
> In this case an implicit default non-const move constructor should be called unless it's also deleted.

If you feel the need to delete const rvalue ref constructors,
why can't you just declared and = default the non-const rvalue
constructor (i.e. the usual move constructor)?

Jens

Received on 2023-12-02 22:00:51