Bug 5897 – unrelated struct type casting should ignite construction

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-27T05:27:00Z
Last change time
2011-06-18T00:01:35Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2011-04-27T05:27:17Z
http://www.digitalmars.com/d/2.0/expression.html > Casting a value v to a struct S, when value is not a struct of the same type, is > equivalent to: > > S(v) This spec explanation includes constructor call in D2, not only static opCall. But current dmd implementation is not. Following code compilation fails with -version=ctor. ---- struct A{ int n; } struct B{ int n, m; version(ctor) { this(A a){ n = a.n, m = a.n*2; } } else { static B opCall(A a) { B b; b.n = a.n, b.m = a.n*2; return b; } } } void main() { auto a = A(10); auto b = cast(B)a; assert(b.n == 10 && b.m == 20); } ----
Comment #1 by k.hara.pg — 2011-04-27T06:21:48Z
Comment #2 by bugzilla — 2011-06-18T00:01:35Z