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
7 changes: 7 additions & 0 deletions changelog/remove_alloc_dealloc.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Class allocators and deallocators are now obsolete

Starting with this release any use of $(LINK2 https://dlang.org/spec/class.html#allocators, class allocators)
or $(LINK2 https://dlang.org/spec/class.html#deallocators, deallocators) will result in a compilation error.

See the $(LINK2 https://dlang.org/deprecate.html#Class%20allocators%20and%20deallocators, deprecated features page)
for more information.
17 changes: 9 additions & 8 deletions src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4315,11 +4315,12 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
//printf("NewDeclaration::semantic()\n");

// `@disable new();` should not be deprecated
if (!nd.isDisabled() && !nd.isDeprecated())
if (!nd.isDisabled())
{
// @@@DEPRECATED_2.084@@@
// Should be changed to an error in 2.084
deprecation(nd.loc, "class allocators have been deprecated, consider moving the allocation strategy outside of the class");
// @@@DEPRECATED_2.091@@@
// Made an error in 2.087.
// Should be removed in 2.091
error(nd.loc, "class allocators are obsolete, consider moving the allocation strategy outside of the class");
}

if (nd.semanticRun >= PASS.semanticdone)
Expand Down Expand Up @@ -4369,10 +4370,10 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
{
//printf("DeleteDeclaration::semantic()\n");

// @@@DEPRECATED_2.084@@@
// Should be changed to an error in 2.084
if (!deld.isDeprecated())
deprecation(deld.loc, "class deallocators have been deprecated, consider moving the deallocation strategy outside of the class");
// @@@DEPRECATED_2.091@@@
// Made an error in 2.087.
// Should be removed in 2.091
error(deld.loc, "class deallocators are obsolete, consider moving the deallocation strategy outside of the class");

if (deld.semanticRun >= PASS.semanticdone)
return;
Expand Down
3 changes: 0 additions & 3 deletions test/compilable/extra-files/header1.d
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ class Test
pure nothrow @safe @nogc unittest {}
pure nothrow @safe @nogc invariant {}
pure nothrow @safe @nogc invariant (true);

pure nothrow @safe @nogc new (size_t sz) { return null; }
pure nothrow @safe @nogc delete (void* p) { }
}

template templ( T )
Expand Down
2 changes: 0 additions & 2 deletions test/compilable/extra-files/header1.di
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ class Test
alias getHUShort = A!ushort;
alias getHReal = A!real;
alias void F();
nothrow pure @nogc @safe new(size_t sz);
nothrow pure @nogc @safe delete(void* p);
}
void templ(T)(T val)
{
Expand Down
7 changes: 0 additions & 7 deletions test/compilable/extra-files/header1i.di
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,6 @@ class Test
alias getHUShort = A!ushort;
alias getHReal = A!real;
alias void F();
nothrow pure @nogc @safe new(size_t sz)
{
return null;
}
nothrow pure @nogc @safe delete(void* p)
{
}
}
void templ(T)(T val)
{
Expand Down
52 changes: 19 additions & 33 deletions test/compilable/vgc1.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,20 @@

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

/*
TEST_OUTPUT:
---
compilable/vgc1.d(17): Deprecation: class allocators have been deprecated, consider moving the allocation strategy outside of the class
compilable/vgc1.d(18): Deprecation: class allocators have been deprecated, consider moving the allocation strategy outside of the class
---
*/

struct S1 { }
struct S2 { this(int); }
struct S3 { this(int) @nogc; }
struct S4 { new(size_t); }
struct S5 { @nogc new(size_t); }

/*
TEST_OUTPUT:
---
compilable/vgc1.d(35): vgc: `new` causes a GC allocation
compilable/vgc1.d(37): vgc: `new` causes a GC allocation
compilable/vgc1.d(38): vgc: `new` causes a GC allocation
compilable/vgc1.d(40): 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(46): vgc: `new` causes a GC allocation
compilable/vgc1.d(25): vgc: `new` causes a GC allocation
compilable/vgc1.d(27): vgc: `new` causes a GC allocation
compilable/vgc1.d(28): vgc: `new` causes a GC allocation
compilable/vgc1.d(30): vgc: `new` causes a GC allocation
compilable/vgc1.d(31): vgc: `new` causes a GC allocation
compilable/vgc1.d(32): vgc: `new` causes a GC allocation
compilable/vgc1.d(34): vgc: `new` causes a GC allocation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing line numbers again, can we use a #line directive for future-proofing ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the test output is fully automated, so this is less work (:

---
*/

Expand All @@ -40,21 +30,19 @@ void testNew()
S1* ps1 = new S1();
S2* ps2 = new S2(1);
S3* ps3 = new S3(1);
S4* ps4 = new S4; // no error
S5* ps5 = new S5; // no error

Object o1 = new Object();
}

/*
TEST_OUTPUT:
---
compilable/vgc1.d(63): vgc: `new` causes a GC allocation
compilable/vgc1.d(65): vgc: `new` causes a GC allocation
compilable/vgc1.d(66): vgc: `new` causes a GC allocation
compilable/vgc1.d(68): 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(51): vgc: `new` causes a GC allocation
compilable/vgc1.d(53): vgc: `new` causes a GC allocation
compilable/vgc1.d(54): vgc: `new` causes a GC allocation
compilable/vgc1.d(56): 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
---
*/

Expand All @@ -68,8 +56,6 @@ void testNewScope()
scope S1* ps1 = new S1();
scope S2* ps2 = new S2(1);
scope S3* ps3 = new S3(1);
scope S4* ps4 = new S4; // no error
scope S5* ps5 = new S5; // no error

scope Object o1 = new Object(); // no error
scope o2 = new Object(); // no error
Expand All @@ -82,12 +68,12 @@ void testNewScope()
/*
TEST_OUTPUT:
---
compilable/vgc1.d(95): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
compilable/vgc1.d(95): vgc: `delete` requires the GC
compilable/vgc1.d(96): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
compilable/vgc1.d(96): vgc: `delete` requires the GC
compilable/vgc1.d(97): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
compilable/vgc1.d(97): vgc: `delete` requires the GC
compilable/vgc1.d(81): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
compilable/vgc1.d(81): vgc: `delete` requires the GC
compilable/vgc1.d(82): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
compilable/vgc1.d(82): vgc: `delete` requires the GC
compilable/vgc1.d(83): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
compilable/vgc1.d(83): vgc: `delete` requires the GC
---
*/
void testDelete(int* p, Object o, S1* s)
Expand Down
23 changes: 23 additions & 0 deletions test/fail_compilation/diag_class_alloc.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag_class_alloc.d(14): Error: class allocators are obsolete, consider moving the allocation strategy outside of the class
fail_compilation/diag_class_alloc.d(19): Error: class deallocators are obsolete, consider moving the deallocation strategy outside of the class
---
*/

// This test exists to ensure class allocators and deallocators emit an appropriate error message.
// This test can be deleted when class allocators and deallocators are removed from the language.

class C
{
new(size_t size) // error message
{
return malloc(size);
}

delete(void* obj) // error message
{
free(obj);
}
}
30 changes: 12 additions & 18 deletions test/fail_compilation/fail14249.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
REQUIRED_ARGS: -unittest
TEST_OUTPUT:
---
fail_compilation/fail14249.d(25): Error: `shared static` constructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(26): Error: `shared static` destructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(27): Error: `static` constructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(28): Error: `static` destructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(29): Error: `unittest` can only be a member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(30): Error: `invariant` can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(31): Error: alias this can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(32): Deprecation: class allocators have been deprecated, consider moving the allocation strategy outside of the class
fail_compilation/fail14249.d(32): Error: allocator can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(33): Deprecation: class deallocators have been deprecated, consider moving the deallocation strategy outside of the class
fail_compilation/fail14249.d(33): Error: deallocator can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(34): Error: constructor can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(35): Error: destructor can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(36): Error: postblit can only be a member of struct, not function `main`
fail_compilation/fail14249.d(37): Error: anonymous union can only be a part of an aggregate, not function `main`
fail_compilation/fail14249.d(41): Error: mixin `fail14249.main.Mix!()` error instantiating
fail_compilation/fail14249.d(21): Error: `shared static` constructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(22): Error: `shared static` destructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(23): Error: `static` constructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(24): Error: `static` destructor can only be member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(25): Error: `unittest` can only be a member of module/aggregate/template, not function `main`
fail_compilation/fail14249.d(26): Error: `invariant` can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(27): Error: alias this can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(28): Error: constructor can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(29): Error: destructor can only be a member of aggregate, not function `main`
fail_compilation/fail14249.d(30): Error: postblit can only be a member of struct, not function `main`
fail_compilation/fail14249.d(31): Error: anonymous union can only be a part of an aggregate, not function `main`
fail_compilation/fail14249.d(35): Error: mixin `fail14249.main.Mix!()` error instantiating
---
*/
mixin template Mix()
Expand All @@ -29,8 +25,6 @@ mixin template Mix()
unittest {}
invariant {}
alias a this;
new(size_t sz) { return null; }
delete(void* p) { }
this() {} // from fail268.d
~this() {} // from fail268.d
this(this) {}
Expand Down
51 changes: 0 additions & 51 deletions test/fail_compilation/fail14407.d

This file was deleted.

Loading