[Issue 18567] New: immutability hole related to context pointers accessed through const pure methods
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 6 22:27:00 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18567
Issue ID: 18567
Summary: immutability hole related to context pointers accessed
through const pure methods
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: timon.gehr at gmx.ch
DMD 2.079.0
void main(){
int i = 0;
struct S{
const(int)* fun()const pure{
return &i;
}
}
immutable S s;
static const(int)* foo(immutable(S) s)pure{
return s.fun();
}
immutable(int) *pi=foo(s);
import std.stdio;
writeln(*pi); // 0
i+=1;
writeln(*pi); // 1
}
I.e. the data *pi is typed as immutable(int), yet changes.
--
More information about the Digitalmars-d-bugs
mailing list