Bug 3977 – Should disable implicit conversion of B[] to A[] when B is derived from A

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-03-16T14:17:00Z
Last change time
2015-06-09T01:31:14Z
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2010-03-16T14:17:50Z
This exposes a potential memory corruption problem: class A {} class B : A {} void proc(A[] x, A y) { x[0] = y; } void main() { B[] anArrayOfB = new B[5]; A a = new A(); proc(anArrayOfB, a); } The solution is to disable implicit conversion of B[] to A[], but B[] to const(A)[] and immutable(B)[] to immutable(A)[] should be allowed.
Comment #1 by schveiguy — 2010-03-16T14:23:00Z
Been around for a while. *** This issue has been marked as a duplicate of issue 2095 ***