Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/deprecate_delete.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The `delete` keyword has been deprecated.

See the $(LINK2 $(ROOT_DIR)deprecate.html#delete, Deprecated Features) for more information.

Starting with this release, using the `delete` keyword will result in a deprecation warning.

As a replacement, users are encouraged to use $(REF1 destroy, object)
if feasible, or $(REF __delete, core,memory) as a last resort.
5 changes: 5 additions & 0 deletions src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -7768,6 +7768,11 @@ final class Parser(AST) : Lexer
case TOK.delete_:
nextToken();
e = parseUnaryExp();
// @@@DEPRECATED_2019-02@@@
// 1. Deprecation for 1 year
// 2. Error for 1 year
// 3. Removal, "delete" can be used for other identities
deprecation("The `delete` keyword has been deprecated. Use `object.destroy()` instead.");
e = new AST.DeleteExp(loc, e, false);
break;

Expand Down
39 changes: 24 additions & 15 deletions test/compilable/vgc1.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
// REQUIRED_ARGS: -vgc -o-
// PERMUTE_ARGS:

/*
TEST_OUTPUT:
---
compilable/vgc1.d(93): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
compilable/vgc1.d(94): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
compilable/vgc1.d(95): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
---
*/

/***************** NewExp *******************/

struct S1 { }
Expand All @@ -12,13 +21,13 @@ struct S5 { @nogc new(size_t); }
/*
TEST_OUTPUT:
---
compilable/vgc1.d(27): vgc: `new` causes a GC allocation
compilable/vgc1.d(29): vgc: `new` causes a GC allocation
compilable/vgc1.d(30): vgc: `new` causes a GC allocation
compilable/vgc1.d(32): vgc: `new` causes a GC allocation
compilable/vgc1.d(33): vgc: `new` causes a GC allocation
compilable/vgc1.d(34): vgc: `new` causes a GC allocation
compilable/vgc1.d(36): vgc: `new` causes a GC allocation
compilable/vgc1.d(38): vgc: `new` causes a GC allocation
compilable/vgc1.d(39): vgc: `new` causes a GC allocation
compilable/vgc1.d(41): vgc: `new` causes a GC allocation
compilable/vgc1.d(42): vgc: `new` causes a GC allocation
compilable/vgc1.d(43): vgc: `new` causes a GC allocation
compilable/vgc1.d(47): vgc: `new` causes a GC allocation
---
*/

Expand All @@ -41,12 +50,12 @@ void testNew()
/*
TEST_OUTPUT:
---
compilable/vgc1.d(55): vgc: `new` causes a GC allocation
compilable/vgc1.d(57): vgc: `new` causes a GC allocation
compilable/vgc1.d(58): vgc: `new` causes a GC allocation
compilable/vgc1.d(60): vgc: `new` causes a GC allocation
compilable/vgc1.d(61): vgc: `new` causes a GC allocation
compilable/vgc1.d(62): vgc: `new` causes a GC allocation
compilable/vgc1.d(64): vgc: `new` causes a GC allocation
compilable/vgc1.d(66): vgc: `new` causes a GC allocation
compilable/vgc1.d(67): vgc: `new` causes a GC allocation
compilable/vgc1.d(69): vgc: `new` causes a GC allocation
compilable/vgc1.d(70): vgc: `new` causes a GC allocation
compilable/vgc1.d(71): vgc: `new` causes a GC allocation
---
*/

Expand Down Expand Up @@ -74,9 +83,9 @@ void testNewScope()
/*
TEST_OUTPUT:
---
compilable/vgc1.d(84): vgc: `delete` requires the GC
compilable/vgc1.d(85): vgc: `delete` requires the GC
compilable/vgc1.d(86): vgc: `delete` requires the GC
compilable/vgc1.d(93): vgc: `delete` requires the GC
compilable/vgc1.d(94): vgc: `delete` requires the GC
compilable/vgc1.d(95): vgc: `delete` requires the GC
---
*/
void testDelete(int* p, Object o, S1* s)
Expand Down
121 changes: 79 additions & 42 deletions test/fail_compilation/fail14486.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
// REQUIRED_ARGS: -o-

/*
TEST_OUTPUT:
---
fail_compilation/fail14486.d(81): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(82): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(83): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(84): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(85): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(99): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(100): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(101): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(102): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(103): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(123): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(124): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(125): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(126): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(127): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(141): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(142): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(143): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(144): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(145): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(164): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(165): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(166): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(167): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(168): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(181): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(182): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(183): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(184): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail14486.d(185): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
---
*/

class C0a { }
class C1a { ~this() {} }
class C2a { ~this() {} @nogc pure @safe delete(void* p) {} }
Expand Down Expand Up @@ -27,18 +63,19 @@ struct S4b { nothrow ~this() {} nothrow delete(void* p) {} }
/*
TEST_OUTPUT:
---
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`
fail_compilation/fail14486.d(46): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C2a.~this`
fail_compilation/fail14486.d(46): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C2a.~this`
fail_compilation/fail14486.d(46): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C2a.~this`
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`
---*/
fail_compilation/fail14486.d(81): Error: `delete c0` is not `@safe` but is used in `@safe` function `test1a`
fail_compilation/fail14486.d(82): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C1a.~this`
fail_compilation/fail14486.d(82): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C1a.~this`
fail_compilation/fail14486.d(82): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C1a.~this`
fail_compilation/fail14486.d(83): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C2a.~this`
fail_compilation/fail14486.d(83): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C2a.~this`
fail_compilation/fail14486.d(83): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C2a.~this`
fail_compilation/fail14486.d(84): Error: `pure` function `fail14486.test1a` cannot call impure deallocator `fail14486.C3a.delete`
fail_compilation/fail14486.d(84): Error: `@safe` function `fail14486.test1a` cannot call `@system` deallocator `fail14486.C3a.delete`
fail_compilation/fail14486.d(84): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc deallocator `fail14486.C3a.delete`
fail_compilation/fail14486.d(85): Error: `delete c4` is not `@safe` but is used in `@safe` function `test1a`
---
*/
void test1a() @nogc pure @safe
{
C0a c0; delete c0; // error
Expand All @@ -51,10 +88,10 @@ void test1a() @nogc pure @safe
/*
TEST_OUTPUT:
---
fail_compilation/fail14486.d(63): Error: destructor `fail14486.C1b.~this` is not `nothrow`
fail_compilation/fail14486.d(64): Error: destructor `fail14486.C2b.~this` is not `nothrow`
fail_compilation/fail14486.d(65): Error: deallocator `fail14486.C3b.delete` is not `nothrow`
fail_compilation/fail14486.d(60): Error: `nothrow` function `fail14486.test1b` may throw
fail_compilation/fail14486.d(100): Error: destructor `fail14486.C1b.~this` is not `nothrow`
fail_compilation/fail14486.d(101): Error: destructor `fail14486.C2b.~this` is not `nothrow`
fail_compilation/fail14486.d(102): Error: deallocator `fail14486.C3b.delete` is not `nothrow`
fail_compilation/fail14486.d(97): Error: `nothrow` function `fail14486.test1b` may throw
---
*/
void test1b() nothrow
Expand All @@ -69,16 +106,16 @@ void test1b() nothrow
/*
TEST_OUTPUT:
---
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`
fail_compilation/fail14486.d(88): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(88): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(88): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(89): Error: `pure` function `fail14486.test2a` cannot call impure deallocator `fail14486.S3a.delete`
fail_compilation/fail14486.d(89): Error: `@safe` function `fail14486.test2a` cannot call `@system` deallocator `fail14486.S3a.delete`
fail_compilation/fail14486.d(89): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc deallocator `fail14486.S3a.delete`
fail_compilation/fail14486.d(123): Error: `delete s0` is not `@safe` but is used in `@safe` function `test2a`
fail_compilation/fail14486.d(124): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S1a.~this`
fail_compilation/fail14486.d(124): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S1a.~this`
fail_compilation/fail14486.d(124): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S1a.~this`
fail_compilation/fail14486.d(125): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(125): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(125): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(126): Error: `pure` function `fail14486.test2a` cannot call impure deallocator `fail14486.S3a.delete`
fail_compilation/fail14486.d(126): Error: `@safe` function `fail14486.test2a` cannot call `@system` deallocator `fail14486.S3a.delete`
fail_compilation/fail14486.d(126): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc deallocator `fail14486.S3a.delete`
---
*/
void test2a() @nogc pure @safe
Expand All @@ -93,10 +130,10 @@ void test2a() @nogc pure @safe
/*
TEST_OUTPUT:
---
fail_compilation/fail14486.d(105): Error: destructor `fail14486.S1b.~this` is not `nothrow`
fail_compilation/fail14486.d(106): Error: destructor `fail14486.S2b.~this` is not `nothrow`
fail_compilation/fail14486.d(107): Error: deallocator `fail14486.S3b.delete` is not `nothrow`
fail_compilation/fail14486.d(102): Error: `nothrow` function `fail14486.test2b` may throw
fail_compilation/fail14486.d(142): Error: destructor `fail14486.S1b.~this` is not `nothrow`
fail_compilation/fail14486.d(143): Error: destructor `fail14486.S2b.~this` is not `nothrow`
fail_compilation/fail14486.d(144): Error: deallocator `fail14486.S3b.delete` is not `nothrow`
fail_compilation/fail14486.d(139): Error: `nothrow` function `fail14486.test2b` may throw
---
*/
void test2b() nothrow
Expand All @@ -111,15 +148,15 @@ void test2b() nothrow
/*
TEST_OUTPUT:
---
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: `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`
fail_compilation/fail14486.d(164): Error: `delete a0` is not `@safe` but is used in `@safe` function `test3a`
fail_compilation/fail14486.d(165): Error: `pure` function `fail14486.test3a` cannot call impure destructor `fail14486.S1a.~this`
fail_compilation/fail14486.d(165): Error: `@safe` function `fail14486.test3a` cannot call `@system` destructor `fail14486.S1a.~this`
fail_compilation/fail14486.d(165): Error: `@nogc` function `fail14486.test3a` cannot call non-@nogc destructor `fail14486.S1a.~this`
fail_compilation/fail14486.d(166): Error: `pure` function `fail14486.test3a` cannot call impure destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(166): Error: `@safe` function `fail14486.test3a` cannot call `@system` destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(166): Error: `@nogc` function `fail14486.test3a` cannot call non-@nogc destructor `fail14486.S2a.~this`
fail_compilation/fail14486.d(167): Error: `delete a3` is not `@safe` but is used in `@safe` function `test3a`
fail_compilation/fail14486.d(168): Error: `delete a4` is not `@safe` but is used in `@safe` function `test3a`
---
*/
void test3a() @nogc pure @safe
Expand All @@ -134,9 +171,9 @@ void test3a() @nogc pure @safe
/*
TEST_OUTPUT:
---
fail_compilation/fail14486.d(145): Error: destructor `fail14486.S1b.~this` is not `nothrow`
fail_compilation/fail14486.d(146): Error: destructor `fail14486.S2b.~this` is not `nothrow`
fail_compilation/fail14486.d(142): Error: `nothrow` function `fail14486.test3b` may throw
fail_compilation/fail14486.d(182): Error: destructor `fail14486.S1b.~this` is not `nothrow`
fail_compilation/fail14486.d(183): Error: destructor `fail14486.S2b.~this` is not `nothrow`
fail_compilation/fail14486.d(179): Error: `nothrow` function `fail14486.test3b` may throw
---
*/
void test3b() nothrow
Expand Down
3 changes: 2 additions & 1 deletion test/fail_compilation/fail2361.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail2361.d(13): Error: cannot modify `immutable` expression `c`
fail_compilation/fail2361.d(14): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
fail_compilation/fail2361.d(14): Error: cannot modify `immutable` expression `c`
---
*/

Expand Down
Loading