Bug 15705 – Invalid memory operation during array growth (@safe code)

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-02-19T14:11:00Z
Last change time
2016-02-20T16:31:06Z
Assigned to
nobody
Creator
matt.elkins

Comments

Comment #0 by matt.elkins — 2016-02-19T14:11:35Z
See this forum discussion for more context: https://forum.dlang.org/post/[email protected] Consider the following code: [code] import std.stdio; @safe: bool scopeEnded; struct Foo { @disable this(this); this(int val) {writeln("Constructing: ", val, " (", &this, ")"); value = val;} ~this() {writeln("Destroying: ", value, " (", &this, ")"); assert(value == int.init || scopeEnded);} int value; } unittest { Foo[] foos; for (auto i = 0; i < 10000; ++i) { ++foos.length; foos[$ - 1] = Foo(i); } writeln("Scope about to end"); scopeEnded = true; } [/code] This yields (among other output): core.exception.InvalidMemoryOperationError@src\core\exception.d(679): Invalid memory operation This occurs during the failed assertion.
Comment #1 by dfj1esp02 — 2016-02-20T16:31:06Z
*** This issue has been marked as a duplicate of issue 7349 ***