http://d.puremagic.com/issues/show_bug.cgi?id=5897

           Summary: unrelated struct type casting should ignite
                    construction
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: k.hara...@gmail.com


--- Comment #0 from Kenji Hara <k.hara...@gmail.com> 2011-04-27 05:27:17 PDT ---
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);
}
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to