Bug 8170 – Incorrect member initialization in associative array of structs

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-30T13:53:00Z
Last change time
2013-09-22T10:51:54Z
Assigned to
nobody
Creator
juhonurm

Comments

Comment #0 by juhonurm — 2012-05-30T13:53:17Z
The code below throws an assert error: void main() { struct S { void* ptr = null; S opAssign(int) { assert (ptr is null); return this; } } S[int] s; s[0] = 0; } In an associative array, ptr is not initialized to null before opAssign is called.
Comment #1 by k.hara.pg — 2013-09-22T10:51:54Z
(In reply to comment #0) > The code below throws an assert error: > > void main() > { > struct S > { > void* ptr = null; > > S opAssign(int) > { > assert (ptr is null); > return this; > } > } > > S[int] s; > s[0] = 0; > } > > In an associative array, ptr is not initialized to null before opAssign is > called. When you call opAssign directly, it would throw RangeError. S[int] s; s[0].opAssign(0); So the OP code should also throw RangeError. *** This issue has been marked as a duplicate of issue 6178 ***