[Issue 14245] Immutable reference to immutable field in constructor allows breaking type system
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Mar 7 00:55:04 PST 2017
https://issues.dlang.org/show_bug.cgi?id=14245
Eduard Staniloiu <edi33416 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |edi33416 at gmail.com
--- Comment #2 from Eduard Staniloiu <edi33416 at gmail.com> ---
Adding another example of this issue.
immutable(int)* g;
struct X {
int a = 10;
immutable this(int x) {
g = &a;
a = 42;
}
}
void main() {
auto x = immutable X();
}
This is problematic in multithreaded environments since the global variable `g`
is shared among threads which rely on it's immutability to provide concurrent,
lock free, accesses.
--
More information about the Digitalmars-d-bugs
mailing list