www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24157] New: [REG2.105] class `this` as lvalue leads to memory

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

          Issue ID: 24157
           Summary: [REG2.105] class `this` as lvalue leads to memory
                    corruption
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

This assertion fails since v2.105:

```
class Promise {
  auto ref unshared() shared {
    return cast() this;
  }
}

pragma(msg, typeof(&Promise.unshared));

void smashStack() {
    char[64] blub;
}

void main() {
  shared p = new Promise;
  Promise* u = &p.unshared();
  smashStack();
  assert(*u is cast() p);
}
```

Almost certainly introduced by the (IMO totally controversial)
https://github.com/dlang/dmd/pull/15389.

--
Sep 25 2023