union mutability
Jack Applegame via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 25 08:22:23 PDT 2016
Code:
union A {
immutable int f;
}
union B {
immutable int f;
int e;
}
void main() {
A a = A(1);
//a = A(2); // a.f is immutable, fails to compile as expected
B b = B(1);
b = B(2); // compiles!!!
}
It turns out that if the union contains at least one mutable
member, then the entire union is considered to be mutable.
It's logical, but does it meet the specs? I couldn't find
description of this behavior.
More information about the Digitalmars-d-learn
mailing list