Bug 14046 – Overlapping dynamic array copy is allowed if struct contains postblit

Status
NEW
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-26T09:20:53Z
Last change time
2024-12-07T13:34:40Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#17289 →

Comments

Comment #0 by verylonglogin.reg — 2015-01-26T09:20:53Z
Overlapping dynamic array copy is now correctly disallowed in CTFE too (Issue 11467) but in runtime this one remaining case is allowed. This code should throw `object.Error` in runtime but doesn't: --- struct S { this(this) { } } void main() { S[1] a; a[0 .. 1] = a[0 .. 1]; } ---
Comment #1 by verylonglogin.reg — 2015-01-26T09:27:43Z
The reason is in case there is no postblit `_d_arraycopy` (which enforces arrays don't overlap [1]) is called for copying and if there is a postblit `_d_arrayassign` (which allows overlapping arrays [2]) is called. [1] https://github.com/D-Programming-Language/druntime/blob/a8c74e00fe21e7781bc6d6fa1773c12b7a1e63b7/src/rt/arraycat.d#L26 [2] https://github.com/D-Programming-Language/druntime/blob/a8c74e00fe21e7781bc6d6fa1773c12b7a1e63b7/src/rt/arrayassign.d#L28
Comment #2 by robert.schadek — 2024-12-07T13:34:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17289 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB