Thread overview
[Issue 5897] New: unrelated struct type casting should ignite construction
Apr 27, 2011
Kenji Hara
Apr 27, 2011
Kenji Hara
Jun 18, 2011
Walter Bright
April 27, 2011
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: nobody@puremagic.com
        ReportedBy: k.hara.pg@gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg@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: -------
April 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5897


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-04-27 06:21:48 PDT ---
Patch posted: https://github.com/D-Programming-Language/dmd/pull/47

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5897


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-06-18 00:01:35 PDT ---
https://github.com/D-Programming-Language/dmd/commit/a0cbf6145dc6c726f40da1f118f851d57797e1bf

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