We cannot use std.exception.enforceEx in @safe function. import std.exception; void test1() @safe { enforceEx!Exception(true, ""); // Error: safe function 'test1' cannot call system function 'enforceEx' } This is dmd bug, using lazy parameter is inferred as unsafe, so whole enforceEx calling is inferred as unsafe. More simple test case. T useLazy(T)(lazy T val) { return val; } void test2() @safe { useLazy(0); // Error: safe function 'test2' cannot call system function 'useLazy' }
https://github.com/D-Programming-Language/dmd/pull/391
https://github.com/D-Programming-Language/dmd/commit/e4fd82fb2c3c2aa5101c8def177ed4e9937e302e
*** Issue 6328 has been marked as a duplicate of this issue. ***