Struct ctor called with cast

Radu void at null.pt
Tue Feb 27 20:30:38 UTC 2018


I have this:

>>>
enum Type { a };
struct S(Type t = Type.a)
{
     this(Type)(Type t)
     {
         import std.stdio;
         writeln("ctor called.");
     }
}
void main()
{
    auto x = S!(Type.a)(Type.a);
    void* y = &x;
    auto z = (cast(S!(Type.a)) y);
}
>>>

Surprisingly the cast will actually call the ctor. Is this to be 
expected? Sure looks like a bug to me, as a non templated S will 
complain about the cast.


More information about the Digitalmars-d-learn mailing list