[Issue 8950] postblit not called on const static array initialization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 17 16:20:11 UTC 2020


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

kinke <kinke at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke at gmx.net

--- Comment #3 from kinke <kinke at gmx.net> ---
Copy ctors are currently (wrongly) ignored when copying static arrays:
https://issues.dlang.org/show_bug.cgi?id=20365

This issue here is pretty bad and inconsistent - the postblit is called
correctly for mutable copies and scalar non-mutable copies, only non-mutable
static array copies ignore the postblit:

void main()
{
    static struct S
    {
        int x = 42;
        this(this) { x += 10; }
    }

    {
        S source;

        S mutableCopy = source;
        assert(mutableCopy.x == 52);

        const S constCopy = source;
        assert(constCopy.x == 52);
    }

    {
        S[1] source;

        auto mutableCopy = source;
        assert(mutableCopy[0].x == 52);

        const constCopy = source;
        assert(constCopy[0].x == 52); // fails

        immutable immutableCopy = source;
        assert(immutableCopy[0].x == 52); // fails
    }
}

--


More information about the Digitalmars-d-bugs mailing list