Struct should be invalid after move
Steven Schveighoffer
schveiguy at gmail.com
Tue Nov 27 15:27:19 UTC 2018
On 11/27/18 3:00 AM, Sebastiaan Koppe wrote:
> I have a non-copyable struct and I really want a compiler error whenever
> I access it after it has been moved.
>
> ---
> struct Handle {
> ...
> @disable this(this);
> ...
> }
>
> void main() {
> import std.algorithm : move;
> auto handle = getOne();
> auto second = handle.move; /// line 14
> auto third = handle.move; /// <- compiler error, variable
> handle is invalid after line 14
> }
> ---
>
> I believe this would prevent some nasty bugs when dealing with these
> structs.
>
> What do you think?
You can do a runtime error (with opPostMove included), but I think a
compiler error would require full flow analysis, and would have to
default to allowing it, as otherwise you will get false errors that are
more annoying than the original problem.
-Steve
More information about the Digitalmars-d
mailing list