Thanks for the explanation! I was confusing myself a bit there because I thought
that once we have moved from an object, its contents don't really matter any
more because it cannot be used further anyway. Objects that have been moved from
are officially in an undefined state, and almost all operations on them other
than destruction are illegal. So I was wondering if code like the one for swap
should be legal (where we assign to b after it has been moved from.)
But *assigning* to such a moved-from object is legal and returns it to a defined
state. I think assigning to it is the only thing that may legally be done with
such an object other than destructing it. Theoretically I should know this, as
I've read up on all that very recently. But I find it hard to keep all these
things in my brain at the same time.
So I see that our implementation (which cleared the task for the moved-from
object while not setting it for the assigned-to one) would be wrong even without
mixing tasks.
>> In any case, the old code was bad. If we wanted operator= from a different task
>> to be illegal, we should have guarded that with an assertion.
> Should I add such an assertion?
Not sure; I find assignment to a state from a different task less strange than
comparison between tasks because in some sense assignment repurposes the object
for something different, so it is a bit like a destruction + construction. I
think we probably don't need the assertion.
>> Is there some other operation we are perhaps not supporting correctly?
> Hard to answer "no" with this given that this bug has been undiscovered since
> the introduction of the State class, which was at least 2 years ago, rather 3 or
> even 4.
This move assignment operator was apparently added on July 2, 2015, but without
the assignment `other.task = nullptr`. That assignment was added when issue791
was merged, in September last year. So until then the swapping would have worked
with states that belong to the same task.
Anyway, the question was more along the lines of "Should we have a look at the
class again and check if there are other issues?". I had a brief look and didn't
see anything, so perhaps that's good enough for now.
|