Allow delete_array(nullptr) and delete_(nullptr)

Issue #114 resolved
Dan Bonachea created an issue

From C++14 [expr.delete]:

In the first alternative (delete object), the value of the operand of delete may be a null pointer value, a pointer to a non-array object created by a previous new-expression, [...]. In the second alternative (delete array), the value of the operand of delete may be a null pointer value or a pointer value that resulted from a previous array new-expression.

However our current Preconditions for upcxx::delete_(g) and upcxx::delete_array(g) include:

g must be a non-deallocated pointer

We should expand this precondition to mirror the behavior of C++ delete, so that we accept delete_array(nullptr) and delete_(nullptr) and treat them as no-ops.

Comments (2)

  1. Dan Bonachea reporter

    I've verified the implementation already contains the null checks to handle this correctly, although there are no tests for this functionality.

  2. Log in to comment