Bug 14783 – Overlapping Arrays with Binary Operations on Itself
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-07T17:34:02Z
Last change time
2022-10-06T10:48:50Z
Assigned to
No Owner
Creator
John Hall
Comments
Comment #0 by john.michael.hall — 2015-07-07T17:34:02Z
The code below will not compile (on DMD 2.067.1) due to an overlapping array error.
void main()
{
int[] x = [0, 1, 2];
x[] *= x[];
}
Neither will it compile with x[] += x[];.
Normally an overlapping error is when you try to do something like
x[1..$] *= x[0..$-1];
However, in this case, there is exact matching. The compiler should be able to detect when it is a case like this and handle it appropriately.
Original discussion here: http://forum.dlang.org/thread/[email protected]
Comment #1 by dlang-bugzilla — 2015-08-31T11:56:47Z
Comment #2 by verylonglogin.reg — 2015-08-31T12:16:31Z
(In reply to Vladimir Panteleev from comment #1)
> I'm not sure if this is a regression or not, but the test case runs fine
> before this PR:
>
> https://github.com/D-Programming-Language/druntime/pull/661
>
> > The code below will not compile
> Will not run
"runs fine"? No, it didn't. It produced an undefined result as there was no support for such case, just lack of a check.
Comment #3 by dlang-bugzilla — 2015-08-31T12:19:28Z
> It produced an undefined result
In what situation would the result be not what the user expected? The test given here works as expected (produces 0,1,4).
Comment #4 by verylonglogin.reg — 2015-08-31T12:23:49Z
(In reply to Vladimir Panteleev from comment #3)
> > It produced an undefined result
>
> In what situation would the result be not what the user expected? The test
> given here works as expected (produces 0,1,4).
I don't now, I can't even guarantee this case exists now because it will require reading all the implementations in different assembly languages. The fact an "undefined behaviour" situation produces an expected result for now doesn't change anything. This functionality is (and was) not officially supported by array functions implementation. Period.
Comment #5 by john.michael.hall — 2015-08-31T13:13:00Z
(In reply to Vladimir Panteleev from comment #3)
> > It produced an undefined result
>
> In what situation would the result be not what the user expected? The test
> given here works as expected (produces 0,1,4).
I've only checked it on the latest versions of DMD (2.067 and 2.068), not before the earlier PR. You're right that it compiles in that I can get an exe. It's just that I can't run the exe.
Comment #6 by razvan.nitu1305 — 2022-10-06T09:44:21Z
The original test case compiles fine now.
Comment #7 by john.michael.hall — 2022-10-06T10:48:50Z
Compiles and runs too (at least with run.dlang.org), which had been part of the problem.