Casting random type to random struct - is this a bug?

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 15 09:03:46 PDT 2015


On Wed, 15 Jul 2015 11:57:01 -0400
Steven Schveighoffer <schveiguy at yahoo.com> wrote:

> On 7/15/15 11:45 AM, rumbu wrote:
> > struct S { int a, b; }
> > auto s = cast(S)10;
> > //compiles and sets s.a to 10.
> >
> > It works also for any other type, if the structure contains a
> > member of that type in the first position.
> >
> > Is this normal behaviour?
> 
> I would say this is a bug. As far as I know, it's not defined in the
> spec.
> 
> -Steve
It is defined:

Casting a value v to a struct S, when value is not a struct of the same
type, is equivalent to:

S(v)


More information about the Digitalmars-d-learn mailing list