diff --git a/src/expression.d b/src/expression.d index a79d6051673b..fcf963e2cfce 100644 --- a/src/expression.d +++ b/src/expression.d @@ -11050,9 +11050,9 @@ extern (C++) final class DeleteExp : UnaExp return new ErrorExp(); } + bool err = false; if (ad) { - bool err = false; if (ad.dtor) { err |= checkPurity(sc, ad.dtor); @@ -11069,6 +11069,15 @@ extern (C++) final class DeleteExp : UnaExp return new ErrorExp(); } + // unsafe + if (!sc.intypeof && sc.func && sc.func.setUnsafe()) + { + error("%s is not @safe but is used in @safe function %s", toChars(), sc.func.toChars()); + err = true; + } + if (err) + return new ErrorExp(); + return this; } diff --git a/test/compilable/nogc.d b/test/compilable/nogc.d index 102f1278e791..c2581da9c26c 100644 --- a/test/compilable/nogc.d +++ b/test/compilable/nogc.d @@ -71,8 +71,8 @@ void test12630() @nogc enum v2 = aa2[1]; Object o; - static const del1 = (delete o).sizeof; - enum del2 = (delete o).sizeof; + //static const del1 = (delete o).sizeof; + //enum del2 = (delete o).sizeof; int[] a; static const len1 = (a.length = 1).sizeof; diff --git a/test/fail_compilation/fail14486.d b/test/fail_compilation/fail14486.d index 14bac4429692..f61770ecc78f 100644 --- a/test/fail_compilation/fail14486.d +++ b/test/fail_compilation/fail14486.d @@ -27,7 +27,7 @@ struct S4b { nothrow ~this() {} nothrow delete(void* p) {} } /* TEST_OUTPUT: --- -fail_compilation/fail14486.d(44): Error: cannot use 'delete' in @nogc function 'fail14486.test1a' +fail_compilation/fail14486.d(44): Error: delete c0 is not @safe but is used in @safe function test1a fail_compilation/fail14486.d(45): Error: pure function 'fail14486.test1a' cannot call impure destructor 'fail14486.C1a.~this' fail_compilation/fail14486.d(45): Error: @safe function 'fail14486.test1a' cannot call @system destructor 'fail14486.C1a.~this' fail_compilation/fail14486.d(45): Error: @nogc function 'fail14486.test1a' cannot call non-@nogc destructor 'fail14486.C1a.~this' @@ -37,8 +37,8 @@ fail_compilation/fail14486.d(46): Error: @nogc function 'fail14486.test1a' canno fail_compilation/fail14486.d(47): Error: pure function 'fail14486.test1a' cannot call impure deallocator 'fail14486.C3a.delete' fail_compilation/fail14486.d(47): Error: @safe function 'fail14486.test1a' cannot call @system deallocator 'fail14486.C3a.delete' fail_compilation/fail14486.d(47): Error: @nogc function 'fail14486.test1a' cannot call non-@nogc deallocator 'fail14486.C3a.delete' ---- -*/ +fail_compilation/fail14486.d(48): Error: delete c4 is not @safe but is used in @safe function test1a +---*/ void test1a() @nogc pure @safe { C0a c0; delete c0; // error @@ -69,7 +69,7 @@ void test1b() nothrow /* TEST_OUTPUT: --- -fail_compilation/fail14486.d(86): Error: cannot use 'delete' in @nogc function 'fail14486.test2a' +fail_compilation/fail14486.d(86): Error: delete s0 is not @safe but is used in @safe function test2a fail_compilation/fail14486.d(87): Error: pure function 'fail14486.test2a' cannot call impure destructor 'fail14486.S1a.~this' fail_compilation/fail14486.d(87): Error: @safe function 'fail14486.test2a' cannot call @system destructor 'fail14486.S1a.~this' fail_compilation/fail14486.d(87): Error: @nogc function 'fail14486.test2a' cannot call non-@nogc destructor 'fail14486.S1a.~this' @@ -111,15 +111,15 @@ void test2b() nothrow /* TEST_OUTPUT: --- -fail_compilation/fail14486.d(127): Error: cannot use 'delete' in @nogc function 'fail14486.test3a' +fail_compilation/fail14486.d(127): Error: delete a0 is not @safe but is used in @safe function test3a fail_compilation/fail14486.d(128): Error: pure function 'fail14486.test3a' cannot call impure destructor 'fail14486.S1a.~this' fail_compilation/fail14486.d(128): Error: @safe function 'fail14486.test3a' cannot call @system destructor 'fail14486.S1a.~this' fail_compilation/fail14486.d(128): Error: @nogc function 'fail14486.test3a' cannot call non-@nogc destructor 'fail14486.S1a.~this' fail_compilation/fail14486.d(129): Error: pure function 'fail14486.test3a' cannot call impure destructor 'fail14486.S2a.~this' fail_compilation/fail14486.d(129): Error: @safe function 'fail14486.test3a' cannot call @system destructor 'fail14486.S2a.~this' fail_compilation/fail14486.d(129): Error: @nogc function 'fail14486.test3a' cannot call non-@nogc destructor 'fail14486.S2a.~this' -fail_compilation/fail14486.d(130): Error: cannot use 'delete' in @nogc function 'fail14486.test3a' -fail_compilation/fail14486.d(131): Error: cannot use 'delete' in @nogc function 'fail14486.test3a' +fail_compilation/fail14486.d(130): Error: delete a3 is not @safe but is used in @safe function test3a +fail_compilation/fail14486.d(131): Error: delete a4 is not @safe but is used in @safe function test3a --- */ void test3a() @nogc pure @safe diff --git a/test/fail_compilation/test16195.d b/test/fail_compilation/test16195.d new file mode 100644 index 000000000000..704974ca30a5 --- /dev/null +++ b/test/fail_compilation/test16195.d @@ -0,0 +1,14 @@ +/* + * TEST_OUTPUT: +--- +fail_compilation/test16195.d(13): Error: delete p is not @safe but is used in @safe function test +--- + */ + + +// https://issues.dlang.org/show_bug.cgi?id=16195 + +@safe pure nothrow @nogc void test(int* p) +{ + delete p; +} diff --git a/test/runnable/xdtor.d b/test/runnable/xdtor.d index a3755617bc2e..df3a4d18c442 100644 --- a/test/runnable/xdtor.d +++ b/test/runnable/xdtor.d @@ -23,7 +23,7 @@ class Bar Field field; } -void test1() @safe @nogc pure nothrow +void test1() @nogc pure nothrow { Foo foo; foo.__xdtor();