Help needed: immutable struct is a type modifier, and that's wrong and broken
FeepingCreature
feepingcreature at gmail.com
Fri Mar 13 09:33:18 UTC 2020
See this bug: https://issues.dlang.org/show_bug.cgi?id=20670
immutable struct S { }
static if(is(S == immutable T, T)) {
static assert(is(S == T));
}
So what happens here is that the spec states that immutable
struct S is "the same as if every member had been marked
immutable." But that's not at all what the compiler actually
does: apparently, it just stores S with an immutable modifier.
As the code shows, immutable modifiers can be stripped away. This
is of course bad, because it means that there's a type "S", but
there's also a type "mutable S" that can only be created by
template specialization or Unqual, and it can't be assigned to S
despite nominally being the exact same type.
Help?
(For now, I'll probably homebrew an Unqual that uses mixin to
figure out when a type has a "fake immutable modifier". But I
won't like it.)
More information about the Digitalmars-d
mailing list