[Issue 22105] New: std.container.array.Array.length setter creates values of init-less types

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 6 05:15:06 UTC 2021


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

          Issue ID: 22105
           Summary: std.container.array.Array.length setter creates values
                    of init-less types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: dlang-bugzilla at thecybershadow.net

//////////////////// test.d ///////////////////
import std.container.array;

struct NonZero
{
    private int n;
    @disable this();
    this(int n) { assert(n != 0); this.n = n; }
    invariant { assert(n != 0); }
    @property int value() const { return n; }
}

void main()
{
    Array!NonZero a;
    a.length = 5;
    assert(a[0].n != 0);
}
///////////////////////////////////////////////

This should not be allowed.

--


More information about the Digitalmars-d-bugs mailing list