[Issue 19928] disallow modification of immutable in constructor after calling base ctor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 4 15:52:23 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19928

Andrei Alexandrescu <andrei at erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei at erdani.com

--- Comment #2 from Andrei Alexandrescu <andrei at erdani.com> ---
This does seem to be a problem. This is liable to cause problems:

import std.stdio : writeln;

struct A
{
    immutable int x;
    this(int)
    {
        foo();
        x = 8;
        foo();
    }

    void foo()
    {   
        passToAnotherThread(&x);
    }       
}

The observing thread assumes the immutable(int)* it receives is, well,
immutable. In reality that value will change over time.

--


More information about the Digitalmars-d-bugs mailing list