Issue 23134 - Mutate variable through immutable pointer
Summary: Mutate variable through immutable pointer
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P3 normal
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2022-05-24 17:33 UTC by Walter Bright
Modified: 2022-12-17 10:37 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2022-05-24 17:33:55 UTC
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
Comment 1 Dlang Bot 2022-05-25 07:08:51 UTC
@WalterBright created dlang/dmd pull request #14164 "fix Issue 23134 - Mutate variable through immutable pointer" fixing this issue:

- fix Issue 23134 - Mutate variable through immutable pointer

https://github.com/dlang/dmd/pull/14164