[Bug c++/115963] P3144R2 is not yet completely implemented with a nullptr constant

de34 at live dot cn gcc-bugzilla@gcc.gnu.org
Wed Jul 17 12:31:19 GMT 2024


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115963

--- Comment #2 from Jiang An <de34 at live dot cn> ---
> The question becomes is that an oversight of P3144R2 or not and should a null pointer
> constant be valid always since that was never undefined or even had a chance of being
> undefined.

CWG2392 (https://cplusplus.github.io/CWG/issues/2392.html) might be related.

In order to keep deleting (constant) null pointer well-formed, we may need to
choose one of following strategies:

1. Make a delete-expression whose operand (after conversion, if any) is a
pointer to an incomplete class type potentially constant evaluated. So that we
can distinguish constant null pointer operand in unevaluated operands (e.g. in
decltype).

2. Always accept such a "bad" delete-expression in unevaluated operands.

Both options reject non-constant and constant but non-null operands.

It seems that GCC is behaving like option 1 (rejecting `decltype(delete
std::declval<Incomplete*>())` while accepting `delete
static_cast<Incomplete*>(nullptr)`).
However, it doesn't seem possible to make it conforming to accept
potentially-evaluated `delete reinterpret_cast<Incomplete*>(std::uintptr_t{})`,
because the operand is not a constant (sub)expression.

On the other hand, I tend to believe "the object being deleted has incomplete
class type" is equivalent to "the pointed to type of the operand is an
incomplete class type", but it's also not very clear whether such reading is
correct.


More information about the Gcc-bugs mailing list