Struct should be invalid after move

Alex sascha.orlov at gmail.com
Tue Nov 27 10:59:03 UTC 2018


On Tuesday, 27 November 2018 at 10:53:21 UTC, Sebastiaan Koppe 
wrote:
>
> Not a trivial problem indeed. But I really believe we need 
> these things (or similar) for safety's sake.
>
> One other issue I can see is if the handle is passed by ref 
> into opaque function. At this point we can't reason about 
> whether the struct is still valid after the call to bar:
>
> ---
> void bar(ref Handle);
>
> void main() {
>   auto handle = getOne();
>   bar(handle);
>   auto second = handle.move(); // compile error? don't know
> }
> ---
>
> Possible solution is to always disallow move after passing as 
> ref.
>
> And maybe move could be disallowed on a scope ref param, then 
> we could safely pass Handle to functions that take by ref while 
> provably keeping the caller's Handle valid.

There exist

auto val = Handle.init;

1. How do you treat this?
2. Why do you don't want to treat the handle after movement the 
same way?


More information about the Digitalmars-d mailing list