https://issues.dlang.org/show_bug.cgi?id=13113
Kenji Hara <k.hara...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version|unspecified |D2 OS|Windows |All Severity|regression |major --- Comment #6 from Kenji Hara <k.hara...@gmail.com> --- This is not a regression, it's a compiler bug around invariant and attributes. Currently dmd implements both post invariant call in constructor and pre invariant call in destructor as direct call. But in normal member functions, pre/post invariant call is done virtually. And, only direct invariant call is affected by the check of pure, @safe, and @nogc attributes. Note that, it is not affected by nothrow but it is not intentional behavior. class C { invariant() {} // impure, throwable, system, and gc-able this(int) pure nothrow @safe @nogc {} // line 5 // post invaiant is called directly and reports attribute violation error ~this() pure nothrow @safe @nogc {} // line 8 // pre invaiant is called directly and reports attribute violation error void foo() pure nothrow @safe @nogc {} // pre/post virtual invariant call does not report attribute violation error } Output: Error: pure function 'test.C.this' cannot call impure function 'test.C.__invariant' test.d(5): Error: safe function 'test.C.this' cannot call system function 'test.C.__invariant' test.d(5): Error: @nogc function 'test.C.this' cannot call non-@nogc function 'test.C.__invariant' Error: pure function 'test.C.~this' cannot call impure function 'test.C.__invariant' test.d(8): Error: safe function 'test.C.~this' cannot call system function 'test.C.__invariant' test.d(8): Error: @nogc function 'test.C.~this' cannot call non-@nogc function 'test.C.__invariant' (In reply to Rainer Schuetze from comment #1) > I'm not 100% sure this is a regression, because the code inside the > invariant changed, too. > Is there a reason why the destructor has to be @safe, pure and @nogc? So, the original issue is not a compiler regression. It was introduced by druntime change in Gcx class invariant code. --