[Issue 23375] enum is not considered global mutable state
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Sep 26 09:59:57 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23375
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
--- Comment #1 from Dennis <dkorpel at live.nl> ---
I thought it would allocate a new array literal in f(), but it really modifies
global state:
```
class C
{
string s;
this(string a) pure @safe nothrow { s = a; }
override string toString() {return s;}
}
enum C[] cs = [ new C("a"), new C("b") ];
void f() pure @safe @nogc nothrow
{
cs[0].s = "c";
}
import std.writeln;
void main()
{
writeln(cs); // [a, b]
f();
writeln(cs); // [c, b]
}
```
I think the could should be accepted without @nogc, and it would modify a copy
of the array.
--
More information about the Digitalmars-d-bugs
mailing list