Thread overview
[Issue 14245] Immutable reference to immutable field in constructor allows breaking type system
Jun 06, 2015
Marc Schütz
Mar 07, 2017
Eduard Staniloiu
Apr 18, 2018
RazvanN
May 26, 2018
RazvanN
June 06, 2015
https://issues.dlang.org/show_bug.cgi?id=14245

--- Comment #1 from Marc Schütz <schuetzm@gmx.net> ---
Full compilable and runnable example (main() was missing):

    struct S {
        immutable int x;
        this(int a) {
            import std.stdio;
            immutable int* b = &this.x;
            writeln(*b); // prints 0
            this.x = a;
            writeln(*b); // prints value of a
        }
    }

    void main() {
        S(10);
    }

--
March 07, 2017
https://issues.dlang.org/show_bug.cgi?id=14245

Eduard Staniloiu <edi33416@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |edi33416@gmail.com

--- Comment #2 from Eduard Staniloiu <edi33416@gmail.com> ---
Adding another example of this issue.

immutable(int)* g;

struct X {
    int a = 10;
    immutable this(int x) {
        g = &a;
        a = 42;
    }
}

void main() {
    auto x = immutable X();
}

This is problematic in multithreaded environments since the global variable `g` is shared among threads which rely on it's immutability to provide concurrent, lock free, accesses.

--
April 18, 2018
https://issues.dlang.org/show_bug.cgi?id=14245

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
PR : https://github.com/dlang/dmd/pull/8189

--
May 26, 2018
https://issues.dlang.org/show_bug.cgi?id=14245

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--