www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22309] New: Taking the address of a stack variable struct

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

          Issue ID: 22309
           Summary: Taking the address of a stack variable struct with
                    this is wrongly seen as  safe
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jlourenco5691 gmail.com

struct Foo
{
    Bar bar()  safe { return Bar(&this); }
}

struct Bar
{
    this(Foo* foo)  safe {}
}

Bar unsafeUnderSafe()  safe
{
        Foo foo;
    return foo.bar;
}

Bar unsafe()  safe
{
        Foo foo;
    return Bar(&foo);
}

void main()  safe
{
    auto b1 = unsafeUnderSafe();
    auto b2 = unsafe();
}

--
Sep 15