[Issue 19348] Struct casts should be better documented.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 25 21:38:52 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=19348

Nick Treleaven <nick at geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick at geany.org

--- Comment #2 from Nick Treleaven <nick at geany.org> ---
Issue 20570 suggests the non-equivalency may be a bug.

> 8. Casting a value v to a struct S, when v is not a struct of the same type,
creates a rvalue of type S, with representation copied from v, with
representation copied from v; no postblits/copy constructors are called;
v.sizeof must be equal to S.sizeof.

No constructor at all seems to be called, unlike for S(v).
That wording would be better, but doesn't explain this error:

struct S {
    int[2] i;
}

void main()
{
    S s;
    s = cast(S) cast(short[4]) [10,0,20,0]; // OK
    s = cast(S) long.max; // error
}

Error: cannot cast expression `9223372036854775807L` of type `long` to `S`

The sizes do match.

--


More information about the Digitalmars-d-bugs mailing list