Feedback Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1

tsbockman thomas.bockman at gmail.com
Thu Mar 11 01:21:08 UTC 2021


On Friday, 5 March 2021 at 12:20:36 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community 
> Review of DIP 1040, "Copying, Moving, and Forwarding".

 From the DIP:
> A Move Assignment Operator is a struct member assignment 
> operator that moves, rather than copies, the argument 
> corresponding to its first parameter into the constructed 
> object. After the move is complete, the destructor is called on 
> the original contents of the constructed object. The argument 
> is invalid after this move, and is not destructed.

This paragraph seems garbled to me.

- What is "the constructed object"? It's ambiguous: presumably 
both `this` and the source argument to the move `opAssign` were 
initialized at some time in the past, otherwise why call the move 
`opAssign` instead of the move constructor? Generally, the phrase 
"the constructed object" is terribly confusing and for clarity 
should be replaced throughout the DIP with less ambiguous 
phrasing, such as "the source of the move" or "the destination of 
the move".

- "After the move is complete, the destructor is called on the 
original contents of the constructed object." This makes no 
sense: the original contents of the destination of the move 
cannot be destroyed *after* the move, as it has already been 
overwritten by the move, and is gone. It would have to either be 
destroyed *before* the move, or copied to a temporary first, 
which seems like a pointless waste.

- If the destination is to be destroyed before the move, then 
there seems to be no need for the separate move `opAssign` at 
all; the compiler should instead just call the destructor on the 
destination, if it has already been initialized, before calling 
the move constructor.

- If there is some good reason for the distinct move `opAssign` 
that I have missed, it should be explained clearly in the DIP.


More information about the Digitalmars-d mailing list