Make delete an identifier instead of keyword (#20745)

This commit is contained in:
Dennis 2025-01-21 23:33:50 +01:00 committed by GitHub
parent f60fc38312
commit 096c9c1528
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 246 additions and 417 deletions

View file

@ -36,9 +36,6 @@ void foo_compiles() {}
static assert(!__traits(compiles, new Struct()));
static assert(!__traits(compiles, new Object()));
int* p;
static assert(!__traits(compiles, delete p));
int[int] aa;
static assert( __traits(compiles, aa[0]));
static assert(!__traits(compiles, (aa[0] = 10)));

View file

@ -1,79 +0,0 @@
// REQUIRED_ARGS: -o-
/*
TEST_OUTPUT:
---
fail_compilation/fail14486.d(47): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(47): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(48): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(48): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(53): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(53): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(54): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(54): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(59): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(59): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(60): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(60): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(65): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(65): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(66): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(66): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(71): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(71): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(72): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(72): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(77): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(77): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail14486.d(78): Error: the `delete` keyword is obsolete
fail_compilation/fail14486.d(78): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
---
*/
class C0a { }
class C1a { ~this() {} }
class C0b { }
class C1b { ~this() {} }
struct S0a { }
struct S1a { ~this() {} }
struct S0b { }
struct S1b { ~this() {} }
void test1a() @nogc pure @safe
{
C0a c0; delete c0; // error
C1a c1; delete c1; // error
}
void test1b() nothrow
{
C0b c0; delete c0; // no error
C1b c1; delete c1; // error
}
void test2a() @nogc pure @safe
{
S0a* s0; delete s0; // error
S1a* s1; delete s1; // error
}
void test2b() nothrow
{
S0b* s0; delete s0; // no error
S1b* s1; delete s1; // error
}
void test3a() @nogc pure @safe
{
S0a[] a0; delete a0; // error
S1a[] a1; delete a1; // error
}
void test3b() nothrow
{
S0b[] a0; delete a0; // no error
S1b[] a1; delete a1; // error
}

View file

@ -1,13 +0,0 @@
// REQUIRED_ARGS: -de
/* TEST_OUTPUT:
---
fail_compilation/fail17906.d(12): Error: the `delete` keyword is obsolete
fail_compilation/fail17906.d(12): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
---
*/
// https://issues.dlang.org/show_bug.cgi?id=18647
deprecated void main ()
{
Object o = new Object;
delete o;
}

View file

@ -1,15 +0,0 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail2361.d(14): Error: the `delete` keyword is obsolete
fail_compilation/fail2361.d(14): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
---
*/
class C {}
void main()
{
immutable c = new immutable(C);
delete c;
}

View file

@ -209,8 +209,6 @@ fail_compilation/fail_arrayop2.d(269): Error: array operation `"abc"[] + '\x01'`
fail_compilation/fail_arrayop2.d(272): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(275): Error: cannot take address of expression `([1] * 6)[0..2]` because it is not an lvalue
fail_compilation/fail_arrayop2.d(278): Error: can only `*` a pointer, not a `int[]`
fail_compilation/fail_arrayop2.d(281): Error: the `delete` keyword is obsolete
fail_compilation/fail_arrayop2.d(281): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/fail_arrayop2.d(284): Error: array operation `da[] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(287): Error: array operation `da[] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(290): Error: cannot modify expression `[1] * 6` because it is not an lvalue
@ -235,6 +233,8 @@ fail_compilation/fail_arrayop2.d(321): Error: array operation `[1] * 6` without
fail_compilation/fail_arrayop2.d(321): Error: array operation `[1] * 6` without destination memory not allowed
---
*/
// Test all expressions, which can take arrays as their operands but cannot be a part of array operation.
void test15407exp()
{
@ -277,8 +277,8 @@ void test15407exp()
// PtrExp, *([1] * 6).ptr is also invalid -> show better diagnostic
{ auto r = *([1] * 6); }
// DeleteExp - e1
delete ([1] * 6);
// TypeDArray.dotExp, cannot check in ArrayLengthExp.semantic()
{ auto r = (6 * da[]).length; }

View file

@ -1,13 +0,0 @@
/*
TEST_OUTPUT:
---
fail_compilation/faildeleteaa.d(12): Error: the `delete` keyword is obsolete
fail_compilation/faildeleteaa.d(12): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
---
*/
void main()
{
int[int] aa = [1 : 2];
delete aa[1];
}

View file

@ -1,9 +0,0 @@
/*
TEST_OUTPUT:
----
fail_compilation/ice11968.d(9): Error: the `delete` keyword is obsolete
fail_compilation/ice11968.d(9): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
----
*/
void main() { delete __FILE__ ; }

View file

@ -57,23 +57,3 @@ fail_compilation/nogc1.d(55): Error: allocating with `new` causes a GC allocatio
scope Object o1 = new Object(); // no error
scope o2 = new Object(); // no error
}
/***************** DeleteExp *******************/
/*
TEST_OUTPUT:
---
fail_compilation/nogc1.d(76): Error: the `delete` keyword is obsolete
fail_compilation/nogc1.d(76): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/nogc1.d(77): Error: the `delete` keyword is obsolete
fail_compilation/nogc1.d(77): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
fail_compilation/nogc1.d(78): Error: the `delete` keyword is obsolete
fail_compilation/nogc1.d(78): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
---
*/
@nogc void testDelete(int* p, Object o, S1* s)
{
delete p;
delete o;
delete s;
}

View file

@ -1,15 +0,0 @@
/*
* TEST_OUTPUT:
---
fail_compilation/test16195.d(14): Error: the `delete` keyword is obsolete
fail_compilation/test16195.d(14): use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead
---
*/
// https://issues.dlang.org/show_bug.cgi?id=16195
@safe pure nothrow @nogc void test(int* p)
{
delete p;
}

View file

@ -383,16 +383,6 @@ void test6714()
assert(bar6714y((a, b){ return a; }) == 2);
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7193
void test7193()
{
static assert(!__traits(compiles, {
delete a => a;
}));
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7207
// on CastExp
@ -1331,7 +1321,6 @@ int main()
test11();
test3235();
test6714();
test7193();
test7202();
test7288();
test7499();

View file

@ -41,11 +41,30 @@ void test1()
assert(Foo.flags == 1);
}
/*********************************************/
// delete is no longer a keyword and can be used as an identifier
enum E
{
add, delete
}
E delete()
{
return E.delete;
}
void test2()
{
assert(delete() == E.delete);
}
/*********************************************/
int main()
{
test1();
test2();
printf("Success\n");
return 0;