https://issues.dlang.org/show_bug.cgi?id=13670
Walter Bright <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #7 from Walter Bright <[email protected]> --- The code is clearly depending on the order of evaluation of a=b, i.e. whether a or b is evaluated first. This is implementation defined in D (as it is in C and C++). My old C/C++ spidey sense goes on red alert, though, when I see code like this. (I still have a hard time figuring out what it's even supposed to do!) It is not actually invalid code - the old array is still there and may have valid references to it. The issue has nothing to do with static arrays, as static arrays cannot be resized. There thing is, if D does define the order of execution of these, either L-R or R-L, it still may not do what a particular programmer expects, and should be cause for suspicion in a code review. I think such dependency should be avoided as a matter of style. The workaround you tried is what the code should be, simply to make its intent clear. There's a lot of merit in your suggestion that such dependency should be flagged as an error, though it won't be detectable in all cases: *foo() = *bar(); What if foo() and bar() have dependent side effects? The compiler can't tell in all cases. --
