[Issue 23134] New: Mutate variable through immutable pointer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 24 17:33:55 UTC 2022


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

          Issue ID: 23134
           Summary: Mutate variable through immutable pointer
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

As reported by deadalnix:

```d
struct S {
     void delegate() dg;
}

void main() {
     int x = 42;
     immutable S s = { dg: () { x++; } };
     s.dg();

     import std.stdio;
     writeln(x);
}
```

This still compiles and run and mutates a variable through an immutable
pointer. This variable could be shared too because immutable is safe to share.

May be related to https://issues.dlang.org/show_bug.cgi?id=16095 and
https://issues.dlang.org/show_bug.cgi?id=1983

--


More information about the Digitalmars-d-bugs mailing list