Skip to content

Commit 11daae8

Browse files
authored
Merge pull request #7342 from JinShil/deprecate_delete
Fix Issue 9433 - Deprecate delete merged-on-behalf-of: unknown
2 parents d03c7ce + f88ab39 commit 11daae8

File tree

9 files changed

+219
-147
lines changed

9 files changed

+219
-147
lines changed

changelog/deprecate_delete.dd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The `delete` keyword has been deprecated.
2+
3+
See the $(LINK2 $(ROOT_DIR)deprecate.html#delete, Deprecated Features) for more information.
4+
5+
Starting with this release, using the `delete` keyword will result in a deprecation warning.
6+
7+
As a replacement, users are encouraged to use $(REF1 destroy, object)
8+
if feasible, or $(REF __delete, core,memory) as a last resort.

src/dmd/parse.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7761,6 +7761,11 @@ final class Parser(AST) : Lexer
77617761
case TOK.delete_:
77627762
nextToken();
77637763
e = parseUnaryExp();
7764+
// @@@DEPRECATED_2019-02@@@
7765+
// 1. Deprecation for 1 year
7766+
// 2. Error for 1 year
7767+
// 3. Removal, "delete" can be used for other identities
7768+
deprecation("The `delete` keyword has been deprecated. Use `object.destroy()` instead.");
77647769
e = new AST.DeleteExp(loc, e, false);
77657770
break;
77667771

test/compilable/vgc1.d

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
// REQUIRED_ARGS: -vgc -o-
22
// PERMUTE_ARGS:
33

4+
/*
5+
TEST_OUTPUT:
6+
---
7+
compilable/vgc1.d(93): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
8+
compilable/vgc1.d(94): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
9+
compilable/vgc1.d(95): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
10+
---
11+
*/
12+
413
/***************** NewExp *******************/
514

615
struct S1 { }
@@ -12,13 +21,13 @@ struct S5 { @nogc new(size_t); }
1221
/*
1322
TEST_OUTPUT:
1423
---
15-
compilable/vgc1.d(27): vgc: `new` causes a GC allocation
16-
compilable/vgc1.d(29): vgc: `new` causes a GC allocation
17-
compilable/vgc1.d(30): vgc: `new` causes a GC allocation
18-
compilable/vgc1.d(32): vgc: `new` causes a GC allocation
19-
compilable/vgc1.d(33): vgc: `new` causes a GC allocation
20-
compilable/vgc1.d(34): vgc: `new` causes a GC allocation
24+
compilable/vgc1.d(36): vgc: `new` causes a GC allocation
2125
compilable/vgc1.d(38): vgc: `new` causes a GC allocation
26+
compilable/vgc1.d(39): vgc: `new` causes a GC allocation
27+
compilable/vgc1.d(41): vgc: `new` causes a GC allocation
28+
compilable/vgc1.d(42): vgc: `new` causes a GC allocation
29+
compilable/vgc1.d(43): vgc: `new` causes a GC allocation
30+
compilable/vgc1.d(47): vgc: `new` causes a GC allocation
2231
---
2332
*/
2433

@@ -41,12 +50,12 @@ void testNew()
4150
/*
4251
TEST_OUTPUT:
4352
---
44-
compilable/vgc1.d(55): vgc: `new` causes a GC allocation
45-
compilable/vgc1.d(57): vgc: `new` causes a GC allocation
46-
compilable/vgc1.d(58): vgc: `new` causes a GC allocation
47-
compilable/vgc1.d(60): vgc: `new` causes a GC allocation
48-
compilable/vgc1.d(61): vgc: `new` causes a GC allocation
49-
compilable/vgc1.d(62): vgc: `new` causes a GC allocation
53+
compilable/vgc1.d(64): vgc: `new` causes a GC allocation
54+
compilable/vgc1.d(66): vgc: `new` causes a GC allocation
55+
compilable/vgc1.d(67): vgc: `new` causes a GC allocation
56+
compilable/vgc1.d(69): vgc: `new` causes a GC allocation
57+
compilable/vgc1.d(70): vgc: `new` causes a GC allocation
58+
compilable/vgc1.d(71): vgc: `new` causes a GC allocation
5059
---
5160
*/
5261

@@ -74,9 +83,9 @@ void testNewScope()
7483
/*
7584
TEST_OUTPUT:
7685
---
77-
compilable/vgc1.d(84): vgc: `delete` requires the GC
78-
compilable/vgc1.d(85): vgc: `delete` requires the GC
79-
compilable/vgc1.d(86): vgc: `delete` requires the GC
86+
compilable/vgc1.d(93): vgc: `delete` requires the GC
87+
compilable/vgc1.d(94): vgc: `delete` requires the GC
88+
compilable/vgc1.d(95): vgc: `delete` requires the GC
8089
---
8190
*/
8291
void testDelete(int* p, Object o, S1* s)

test/fail_compilation/fail14486.d

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
// REQUIRED_ARGS: -o-
22

3+
/*
4+
TEST_OUTPUT:
5+
---
6+
fail_compilation/fail14486.d(81): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
7+
fail_compilation/fail14486.d(82): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
8+
fail_compilation/fail14486.d(83): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
9+
fail_compilation/fail14486.d(84): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
10+
fail_compilation/fail14486.d(85): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
11+
fail_compilation/fail14486.d(99): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
12+
fail_compilation/fail14486.d(100): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
13+
fail_compilation/fail14486.d(101): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
14+
fail_compilation/fail14486.d(102): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
15+
fail_compilation/fail14486.d(103): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
16+
fail_compilation/fail14486.d(123): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
17+
fail_compilation/fail14486.d(124): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
18+
fail_compilation/fail14486.d(125): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
19+
fail_compilation/fail14486.d(126): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
20+
fail_compilation/fail14486.d(127): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
21+
fail_compilation/fail14486.d(141): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
22+
fail_compilation/fail14486.d(142): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
23+
fail_compilation/fail14486.d(143): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
24+
fail_compilation/fail14486.d(144): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
25+
fail_compilation/fail14486.d(145): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
26+
fail_compilation/fail14486.d(164): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
27+
fail_compilation/fail14486.d(165): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
28+
fail_compilation/fail14486.d(166): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
29+
fail_compilation/fail14486.d(167): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
30+
fail_compilation/fail14486.d(168): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
31+
fail_compilation/fail14486.d(181): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
32+
fail_compilation/fail14486.d(182): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
33+
fail_compilation/fail14486.d(183): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
34+
fail_compilation/fail14486.d(184): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
35+
fail_compilation/fail14486.d(185): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
36+
---
37+
*/
38+
339
class C0a { }
440
class C1a { ~this() {} }
541
class C2a { ~this() {} @nogc pure @safe delete(void* p) {} }
@@ -27,18 +63,19 @@ struct S4b { nothrow ~this() {} nothrow delete(void* p) {} }
2763
/*
2864
TEST_OUTPUT:
2965
---
30-
fail_compilation/fail14486.d(44): Error: `delete c0` is not `@safe` but is used in `@safe` function `test1a`
31-
fail_compilation/fail14486.d(45): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C1a.~this`
32-
fail_compilation/fail14486.d(45): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C1a.~this`
33-
fail_compilation/fail14486.d(45): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C1a.~this`
34-
fail_compilation/fail14486.d(46): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C2a.~this`
35-
fail_compilation/fail14486.d(46): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C2a.~this`
36-
fail_compilation/fail14486.d(46): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C2a.~this`
37-
fail_compilation/fail14486.d(47): Error: `pure` function `fail14486.test1a` cannot call impure deallocator `fail14486.C3a.delete`
38-
fail_compilation/fail14486.d(47): Error: `@safe` function `fail14486.test1a` cannot call `@system` deallocator `fail14486.C3a.delete`
39-
fail_compilation/fail14486.d(47): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc deallocator `fail14486.C3a.delete`
40-
fail_compilation/fail14486.d(48): Error: `delete c4` is not `@safe` but is used in `@safe` function `test1a`
41-
---*/
66+
fail_compilation/fail14486.d(81): Error: `delete c0` is not `@safe` but is used in `@safe` function `test1a`
67+
fail_compilation/fail14486.d(82): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C1a.~this`
68+
fail_compilation/fail14486.d(82): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C1a.~this`
69+
fail_compilation/fail14486.d(82): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C1a.~this`
70+
fail_compilation/fail14486.d(83): Error: `pure` function `fail14486.test1a` cannot call impure destructor `fail14486.C2a.~this`
71+
fail_compilation/fail14486.d(83): Error: `@safe` function `fail14486.test1a` cannot call `@system` destructor `fail14486.C2a.~this`
72+
fail_compilation/fail14486.d(83): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc destructor `fail14486.C2a.~this`
73+
fail_compilation/fail14486.d(84): Error: `pure` function `fail14486.test1a` cannot call impure deallocator `fail14486.C3a.delete`
74+
fail_compilation/fail14486.d(84): Error: `@safe` function `fail14486.test1a` cannot call `@system` deallocator `fail14486.C3a.delete`
75+
fail_compilation/fail14486.d(84): Error: `@nogc` function `fail14486.test1a` cannot call non-@nogc deallocator `fail14486.C3a.delete`
76+
fail_compilation/fail14486.d(85): Error: `delete c4` is not `@safe` but is used in `@safe` function `test1a`
77+
---
78+
*/
4279
void test1a() @nogc pure @safe
4380
{
4481
C0a c0; delete c0; // error
@@ -51,10 +88,10 @@ void test1a() @nogc pure @safe
5188
/*
5289
TEST_OUTPUT:
5390
---
54-
fail_compilation/fail14486.d(63): Error: destructor `fail14486.C1b.~this` is not `nothrow`
55-
fail_compilation/fail14486.d(64): Error: destructor `fail14486.C2b.~this` is not `nothrow`
56-
fail_compilation/fail14486.d(65): Error: deallocator `fail14486.C3b.delete` is not `nothrow`
57-
fail_compilation/fail14486.d(60): Error: `nothrow` function `fail14486.test1b` may throw
91+
fail_compilation/fail14486.d(100): Error: destructor `fail14486.C1b.~this` is not `nothrow`
92+
fail_compilation/fail14486.d(101): Error: destructor `fail14486.C2b.~this` is not `nothrow`
93+
fail_compilation/fail14486.d(102): Error: deallocator `fail14486.C3b.delete` is not `nothrow`
94+
fail_compilation/fail14486.d(97): Error: `nothrow` function `fail14486.test1b` may throw
5895
---
5996
*/
6097
void test1b() nothrow
@@ -69,16 +106,16 @@ void test1b() nothrow
69106
/*
70107
TEST_OUTPUT:
71108
---
72-
fail_compilation/fail14486.d(86): Error: `delete s0` is not `@safe` but is used in `@safe` function `test2a`
73-
fail_compilation/fail14486.d(87): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S1a.~this`
74-
fail_compilation/fail14486.d(87): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S1a.~this`
75-
fail_compilation/fail14486.d(87): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S1a.~this`
76-
fail_compilation/fail14486.d(88): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S2a.~this`
77-
fail_compilation/fail14486.d(88): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S2a.~this`
78-
fail_compilation/fail14486.d(88): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S2a.~this`
79-
fail_compilation/fail14486.d(89): Error: `pure` function `fail14486.test2a` cannot call impure deallocator `fail14486.S3a.delete`
80-
fail_compilation/fail14486.d(89): Error: `@safe` function `fail14486.test2a` cannot call `@system` deallocator `fail14486.S3a.delete`
81-
fail_compilation/fail14486.d(89): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc deallocator `fail14486.S3a.delete`
109+
fail_compilation/fail14486.d(123): Error: `delete s0` is not `@safe` but is used in `@safe` function `test2a`
110+
fail_compilation/fail14486.d(124): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S1a.~this`
111+
fail_compilation/fail14486.d(124): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S1a.~this`
112+
fail_compilation/fail14486.d(124): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S1a.~this`
113+
fail_compilation/fail14486.d(125): Error: `pure` function `fail14486.test2a` cannot call impure destructor `fail14486.S2a.~this`
114+
fail_compilation/fail14486.d(125): Error: `@safe` function `fail14486.test2a` cannot call `@system` destructor `fail14486.S2a.~this`
115+
fail_compilation/fail14486.d(125): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc destructor `fail14486.S2a.~this`
116+
fail_compilation/fail14486.d(126): Error: `pure` function `fail14486.test2a` cannot call impure deallocator `fail14486.S3a.delete`
117+
fail_compilation/fail14486.d(126): Error: `@safe` function `fail14486.test2a` cannot call `@system` deallocator `fail14486.S3a.delete`
118+
fail_compilation/fail14486.d(126): Error: `@nogc` function `fail14486.test2a` cannot call non-@nogc deallocator `fail14486.S3a.delete`
82119
---
83120
*/
84121
void test2a() @nogc pure @safe
@@ -93,10 +130,10 @@ void test2a() @nogc pure @safe
93130
/*
94131
TEST_OUTPUT:
95132
---
96-
fail_compilation/fail14486.d(105): Error: destructor `fail14486.S1b.~this` is not `nothrow`
97-
fail_compilation/fail14486.d(106): Error: destructor `fail14486.S2b.~this` is not `nothrow`
98-
fail_compilation/fail14486.d(107): Error: deallocator `fail14486.S3b.delete` is not `nothrow`
99-
fail_compilation/fail14486.d(102): Error: `nothrow` function `fail14486.test2b` may throw
133+
fail_compilation/fail14486.d(142): Error: destructor `fail14486.S1b.~this` is not `nothrow`
134+
fail_compilation/fail14486.d(143): Error: destructor `fail14486.S2b.~this` is not `nothrow`
135+
fail_compilation/fail14486.d(144): Error: deallocator `fail14486.S3b.delete` is not `nothrow`
136+
fail_compilation/fail14486.d(139): Error: `nothrow` function `fail14486.test2b` may throw
100137
---
101138
*/
102139
void test2b() nothrow
@@ -111,15 +148,15 @@ void test2b() nothrow
111148
/*
112149
TEST_OUTPUT:
113150
---
114-
fail_compilation/fail14486.d(127): Error: `delete a0` is not `@safe` but is used in `@safe` function `test3a`
115-
fail_compilation/fail14486.d(128): Error: `pure` function `fail14486.test3a` cannot call impure destructor `fail14486.S1a.~this`
116-
fail_compilation/fail14486.d(128): Error: `@safe` function `fail14486.test3a` cannot call `@system` destructor `fail14486.S1a.~this`
117-
fail_compilation/fail14486.d(128): Error: `@nogc` function `fail14486.test3a` cannot call non-@nogc destructor `fail14486.S1a.~this`
118-
fail_compilation/fail14486.d(129): Error: `pure` function `fail14486.test3a` cannot call impure destructor `fail14486.S2a.~this`
119-
fail_compilation/fail14486.d(129): Error: `@safe` function `fail14486.test3a` cannot call `@system` destructor `fail14486.S2a.~this`
120-
fail_compilation/fail14486.d(129): Error: `@nogc` function `fail14486.test3a` cannot call non-@nogc destructor `fail14486.S2a.~this`
121-
fail_compilation/fail14486.d(130): Error: `delete a3` is not `@safe` but is used in `@safe` function `test3a`
122-
fail_compilation/fail14486.d(131): Error: `delete a4` is not `@safe` but is used in `@safe` function `test3a`
151+
fail_compilation/fail14486.d(164): Error: `delete a0` is not `@safe` but is used in `@safe` function `test3a`
152+
fail_compilation/fail14486.d(165): Error: `pure` function `fail14486.test3a` cannot call impure destructor `fail14486.S1a.~this`
153+
fail_compilation/fail14486.d(165): Error: `@safe` function `fail14486.test3a` cannot call `@system` destructor `fail14486.S1a.~this`
154+
fail_compilation/fail14486.d(165): Error: `@nogc` function `fail14486.test3a` cannot call non-@nogc destructor `fail14486.S1a.~this`
155+
fail_compilation/fail14486.d(166): Error: `pure` function `fail14486.test3a` cannot call impure destructor `fail14486.S2a.~this`
156+
fail_compilation/fail14486.d(166): Error: `@safe` function `fail14486.test3a` cannot call `@system` destructor `fail14486.S2a.~this`
157+
fail_compilation/fail14486.d(166): Error: `@nogc` function `fail14486.test3a` cannot call non-@nogc destructor `fail14486.S2a.~this`
158+
fail_compilation/fail14486.d(167): Error: `delete a3` is not `@safe` but is used in `@safe` function `test3a`
159+
fail_compilation/fail14486.d(168): Error: `delete a4` is not `@safe` but is used in `@safe` function `test3a`
123160
---
124161
*/
125162
void test3a() @nogc pure @safe
@@ -134,9 +171,9 @@ void test3a() @nogc pure @safe
134171
/*
135172
TEST_OUTPUT:
136173
---
137-
fail_compilation/fail14486.d(145): Error: destructor `fail14486.S1b.~this` is not `nothrow`
138-
fail_compilation/fail14486.d(146): Error: destructor `fail14486.S2b.~this` is not `nothrow`
139-
fail_compilation/fail14486.d(142): Error: `nothrow` function `fail14486.test3b` may throw
174+
fail_compilation/fail14486.d(182): Error: destructor `fail14486.S1b.~this` is not `nothrow`
175+
fail_compilation/fail14486.d(183): Error: destructor `fail14486.S2b.~this` is not `nothrow`
176+
fail_compilation/fail14486.d(179): Error: `nothrow` function `fail14486.test3b` may throw
140177
---
141178
*/
142179
void test3b() nothrow

test/fail_compilation/fail2361.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
TEST_OUTPUT:
33
---
4-
fail_compilation/fail2361.d(13): Error: cannot modify `immutable` expression `c`
4+
fail_compilation/fail2361.d(14): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` instead.
5+
fail_compilation/fail2361.d(14): Error: cannot modify `immutable` expression `c`
56
---
67
*/
78

0 commit comments

Comments
 (0)