[Issue 24298] New: cpp_delete should check for null
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 22 13:10:33 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24298
Issue ID: 24298
Summary: cpp_delete should check for null
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: tim.dlang at t-online.de
Function core.stdcpp.new_.cpp_delete is the equivalent of the delete operator
in C++, which can be called with a null pointer and ignores it. Calling
cpp_delete with a null pointer can currently result in a crash, which makes
porting of C++ code to D harder.
unittest
{
import core.stdcpp.new_: cpp_new, cpp_delete;
extern(C++) static struct S
{
__gshared int numDeleted;
__gshared int lastDeleted;
int i;
~this()
{
lastDeleted = i;
numDeleted++;
}
}
S *s = cpp_new!S(12345);
cpp_delete(s);
assert(S.numDeleted == 1);
assert(S.lastDeleted == 12345);
s = null;
cpp_delete(s);
assert(S.numDeleted == 1);
assert(S.lastDeleted == 12345);
}
--
More information about the Digitalmars-d-bugs
mailing list