You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of DMD 2.109.1, the example program below compiles and runs to completion without errors.
The program uses core.lifetime.emplace to mutate immutable data in @safe code. Since mutating immutable data results in undefined behavior, it is a bug for the program to compile.
The cause of the bug is the use of @trusted in core.lifetime.emplace to cast away type qualifiers from the target object.
---
import core.lifetime;
void example1() @safe
{
const(int)* obj = new immutable(int)(123);
assert(*obj == 123);
emplace(obj, 456);
assert(*obj == 456); // immutable object mutated!
}
void example2() @safe
{
static class C
{
int n;
this(int n) pure @safe { this.n = n; }
}
const(C) obj = new immutable(C)(123);assert(obj.n == 123);emplace(obj, 456);assert(obj.n == 456); // immutable object mutated!
}
void example3() @safe
{
static struct S
{
int n;
this(int n) pure @safe { this.n = n; }
}
const(S)* obj = new immutable(S)(123);assert(obj.n == 123);emplace(obj, 456);assert(obj.n == 456); // immutable object mutated!
}
void main() @safe
{
example1();
example2();
example3();
}
---
The text was updated successfully, but these errors were encountered:
Paul Backus (@pbackus) reported this on 2024-10-04T16:45:52Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=24795
Description
The text was updated successfully, but these errors were encountered: