Skip to content

Commit

Permalink
fix Issue 16195 - delete should be @System
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 30, 2016
1 parent 5ca4b33 commit e64ae1d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions test/compilable/nogc.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions test/fail_compilation/fail14486.d
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/fail_compilation/test16195.d
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion test/runnable/xdtor.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Bar
Field field;
}

void test1() @safe @nogc pure nothrow
void test1() @nogc pure nothrow
{
Foo foo;
foo.__xdtor();
Expand Down

0 comments on commit e64ae1d

Please sign in to comment.