Struct should be invalid after move

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Nov 27 13:03:06 UTC 2018


On Tuesday, November 27, 2018 5:37:29 AM MST Stanislav Blinov via 
Digitalmars-d wrote:
> On Tuesday, 27 November 2018 at 12:14:17 UTC, Jonathan M Davis
>
> wrote:
> > Well, if the compiler were doing the move...
>
> [wall snipped]
>
> > And simply flagging common functions that do moves isn't going
> > to be enough to catch all cases - especially when all it takes
> > to hide the fact that a move occurred is to wrap the move call
> > in another function that the compiler doesn't have visibility
> > into thanks to separate compilation.
>
> "Easy" enough. The move and emplace families should be compiler
> intrinsics, not library functions.

Well, they're not currently. And even if they were, that doesn't solve the
problem of detecting when functions are called that do moves that the
compiler does not have the source code for due to separate compilation or
because the move is actually being done in C code that gets called from D
code. Without that, at best, you're catching the really simple cases, and
even that likely requires code flow analysis. It also has the problem that
it gives the impression that the compiler catches a certain class of problem
for you in general when in fact it only catches it in a few cases. It's
basically getting into the same territory as detecting when a pointer or
reference is never initialized with anything other null and making that an
error - something that Walter has already refused to do, because only the
most basic cases would be caught (especially if you want to avoid false
positives), and he doesn't want to add features that require code flow
analysis.

Honestly, this seems like the sort of thing that's better suited to a linter
that detects some cases where it thinks you might be accessing a variable in
an invalid manner after it's been moved (allowing you to examine the code to
see whether it's right or not), whereas the compiler has to get it right
100% of the time - especially if it's an error.

- Jonathan M Davis





More information about the Digitalmars-d mailing list