The same already applies for invariants, you shouldn't be able to modify internal state inside a in/out contract body. e.g: --- struct S { int a; invariant { a = 42; } // fails, cannot modify const 'this' this(int n) in { a = 42; } // compiles -> should fail out(result) { a = 42; } // compiles -> should fail body { } } --- This is particularly problematic because program behaviour changes in release mode.
See also comments in issue 12901
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/3d024cb20277826a428ac616a7324be027843122 fix Issue 18143 - in/out contracts should be implicitly 'this' const https://github.com/dlang/dmd/commit/4c7ea172c8f1c714fe85a3fda54ec2ddfc0598f1 Merge pull request #7553 from ibuclaw/issue18143 fix Issue 18143 - in/out contracts should be implicitly 'this' const merged-on-behalf-of: Mike Franklin <JinShil@users.noreply.github.com>
dlang/dmd pull request #12153 "[dmd-cxx] Backport fixes for issue 18143 and 18719." was merged into dmd-cxx: - b6e4baefe04777e905a61c7d1291a9ed691a8698 by Iain Buclaw: fix Issue 18143 - in/out contracts should be implicitly 'this' const https://github.com/dlang/dmd/pull/12153