union mutability

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 25 10:01:40 PDT 2016


On Thursday, 25 August 2016 at 15:22:23 UTC, Jack Applegame wrote:
> 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.

This should be fixed pretty soon: 
https://github.com/dlang/dmd/pull/5940


More information about the Digitalmars-d-learn mailing list