[Issue 19731] New: auto struct methods whose address is taken don't test invariants

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 12 14:10:55 UTC 2019


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

          Issue ID: 19731
           Summary: auto struct methods whose address is taken don't test
                    invariants
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

Consider the following code:

struct Foo
{
    Object obj_;

    invariant (obj_ !is null);

    auto obj()
    {
        return this.obj_;
    }

    enum compiles = __traits(compiles, &Foo.init.obj);
}

void main()
{
    Foo foo = Foo();

    foo.obj.toString();
}

foo.obj should hit the invariant, but because Foo.obj straight up does not call
the invariant check at all, we instead hit a segfault in toString.

The code works if the return type is not auto, or if the `enum compiles` line
is removed.

--


More information about the Digitalmars-d-bugs mailing list