Bug 12889 – std.array replaceInPlace overlapping array copy error

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-11T15:03:00Z
Last change time
2014-06-17T18:43:41Z
Keywords
pull
Assigned to
nobody
Creator
safety0ff.bugz

Comments

Comment #0 by safety0ff.bugz — 2014-06-11T15:03:13Z
Trying to remove anything but the a single element from the front of a multidimensional array will cause a run time error. This causes bugs in phobos functions who depend on remove such as replaceInPlace. Code: import std.typecons; import std.algorithm; import std.stdio : writeln; void main() { // note: dimension doesn't matter int[1][] arr = [[0], [1], [2], [3], [4], [5], [6]]; size_t from = 1; // from is inclusive size_t to = 2; // to is exclusive //arr = remove(arr, tuple(from,to)); // object.Error: overlapping array copy //foreach (i; from .. to) arr = remove(arr, i); // object.Error: overlapping array copy arr = remove(arr, 0); // Ok! //arr = remove(arr, 1); // object.Error: overlapping array copy // even removing nothing is broken: //arr = remove(arr, tuple(0,0)); // object.Error: overlapping array copy writeln(arr); }
Comment #1 by safety0ff.bugz — 2014-06-11T15:04:51Z
(In reply to safety0ff.bugz from comment #0) > Trying to remove anything but the a single element from the front of a > multidimensional array will cause a run time error. I obviously meant array of arrays instead of multidimensional.
Comment #2 by safety0ff.bugz — 2014-06-11T22:13:03Z
This is really a replaceInPlace issue, sorry for the noise. https://github.com/D-Programming-Language/phobos/pull/2239
Comment #3 by safety0ff.bugz — 2014-06-16T23:48:52Z
Fixed by commit: https://github.com/D-Programming-Language/dmd/commit/dd0cf86b43877b18c0e93830b193a48ad66ff17a *** This issue has been marked as a duplicate of issue 12212 ***
Comment #4 by github-bugzilla — 2014-06-17T18:43:41Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/6ff3378c79d5b111c1c26f29b0551be3de9e1b49 Add unittests bug #12889 https://github.com/D-Programming-Language/phobos/commit/00844d30bbac8c3473609dd00c30f595ab1e479b Merge pull request #2239 from Safety0ff/fix12889 Unit tests for bug #12889 - replaceInPlace overlapping array copy error