C++ Logo

std-discussion

Advanced search

Re: another potential ambiguity for assign.op.

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sat, 4 Jul 2026 18:54:43 +0300
On Sat, 4 Jul 2026 at 18:18, mauro russo via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> in [class.copy.assign]-p(12.3) :
>
> It is unspecified whether subobjects representing virtual base
> classes are assigned more than once by the implicitly-defined
> copy/move assignment operator.
>
>
> I see no problem here about copy-case, but for the move-case,
> wouldn't it be an error to move more than once ?
> Is it really unspecified whether the compiler would perform the
> move more than once ? It's like inhibiting the use of the implicit
> definition for virtual base classes where move-semantics makes
> sense. I mean, if the first move changes the source subobject
> state, then second move would get from the subobject which
> by then has a modified state.
> Is there any other rule to in the standard that forces the compiler
> to assure a consistent result ? (e.g., leading to unspecified
> multiple move only in case move falls back to copy).

It is really unspecified, there is no such other rule, and GCC and
Clang do move-assign the virtual base subobject twice:
https://godbolt.org/z/PK3GEav13

Program accordingly.

Received on 2026-07-04 15:55:00