[Issue 13670] bug in assigning to dynamic array element
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Nov 28 20:30:14 PST 2014
https://issues.dlang.org/show_bug.cgi?id=13670
Walter Bright <bugzilla at digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugzilla at digitalmars.com
--- Comment #7 from Walter Bright <bugzilla at digitalmars.com> ---
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.
--
More information about the Digitalmars-d-bugs
mailing list