Date: Thu, 6 Aug 2020 21:19:22 +0000 (UTC)
On Thursday, August 6, 2020, 3:57:11 PM CDT, Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote:
On Thu, 6 Aug 2020 at 23:49, Walt Karas via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> If a class C has a copy constructor, seems desirable to generate a default copy assign like:
>
>
> C & operator = (C const &rhs)
> {
> if (this != &rhs)
> {
>
> this->~C();
> ::new (this) C(rhs);
> }
> return *this;
> }
>
>
> Likewise for default move assign when move copy is defined:
>
>
> C & operator = (C &&rhs)
>
> {
> if (this != &rhs)
> {
>
> this->~C();
> ::new (this) C(std::move(rhs));
> }
> return *this;
Those definitions are not exception-safe, so I'd find it questionable
to generate them by default.
WK: Good point, they should be noexcept if the corresponding constructor is noexcept (and the destructor).
On Thu, 6 Aug 2020 at 23:49, Walt Karas via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> If a class C has a copy constructor, seems desirable to generate a default copy assign like:
>
>
> C & operator = (C const &rhs)
> {
> if (this != &rhs)
> {
>
> this->~C();
> ::new (this) C(rhs);
> }
> return *this;
> }
>
>
> Likewise for default move assign when move copy is defined:
>
>
> C & operator = (C &&rhs)
>
> {
> if (this != &rhs)
> {
>
> this->~C();
> ::new (this) C(std::move(rhs));
> }
> return *this;
Those definitions are not exception-safe, so I'd find it questionable
to generate them by default.
WK: Good point, they should be noexcept if the corresponding constructor is noexcept (and the destructor).
Received on 2020-08-06 16:22:53