Bug 12198 – Catch some wrong overlapping array operations at compile time

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-02-18T13:40:56Z
Last change time
2024-12-13T18:17:07Z
Keywords
diagnostic
Assigned to
Lionello Lunesu
Creator
bearophile_hugs
Moved to GitHub: dmd#17640 →

Comments

Comment #0 by bearophile_hugs — 2014-02-18T13:40:56Z
void main() { int[1] a, b; a[] = a[]; a[] = a[] + b[]; a[] = a[] * 2; } With DMD 2.065rc1 that code compiles, and then it gives at run-time: object.Error: Overlapping arrays in vector operation: 4 byte(s) overlap of 4 I suggest to catch similar basic cases at compile-time.
Comment #1 by lio+bugzilla — 2016-05-16T11:34:44Z
I ran into this as well and also think the compiler should make a best effort to detect this at compile time, to minimize run-time surprises. I'm pretty far along with a patch, but am running into corner cases. Will push soon to get some feedback.
Comment #2 by nick — 2023-07-05T13:16:11Z
With dmd v2.104.0, this is the only line that fails: > a[] = a[]; Even this works: a[] = b[] / a[]; So it's not just rewriting it as `op=`.
Comment #3 by robert.schadek — 2024-12-13T18:17:07Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17640 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB