Struct should be invalid after move

Steven Schveighoffer schveiguy at gmail.com
Tue Nov 27 19:28:13 UTC 2018


On 11/27/18 11:49 AM, burjui wrote:
> On Tuesday, 27 November 2018 at 15:27:19 UTC, Steven Schveighoffer wrote:
>> 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.
> 
> A good modern compiler of a statically compiled language has to have 
> flow analysis enabled unconditionally.

Does g++ count as a modern compiler? It doesn't do flow analysis on the 
code you have below.

> I 
> find it sad and ridiculous at the same time. This happens exactly 
> because dataflow analysis is only enabled when optimizations are enabled:
> 
> void main()
> {
>      int* x;
>      *x = 0;
> }
> 
> This compiles just fine with `dmd x.d`, but emits an error with `dmd -O 
> x.d`:
> Error: null dereference in function _Dmain

Note that complete flow analysis is equivalent to the halting problem. 
So really, you can never get it perfect, and therefore, there are always 
going to be some things you can't catch. So it's impossible to fulfill 
that promise in any compiler.

In any case, I can't imagine how to do it without some handshaking 
between std.algorithm.move and the compiler, which is likely to be met 
with resistance.

-Steve


More information about the Digitalmars-d mailing list