www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19731] New: auto struct methods whose address is taken don't

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 puremagic.com
          Reporter: default_357-line 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.

--
Mar 12 2019