-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter (unless configured in github; will be published with the issue): Jiang An
Reference (section label): [expr.delete]
Link to reflector thread (if any):
Issue description:
Paper P3144R2 only made deleting a pointer of pointer to incomplete class type ill-formed, which didn't match its title (Deleting a Pointer to an Incomplete Type Should be Ill-formed), since it's possible to form a delete-expression whose operand is of poiner to incomplete enumeration type.
A counterexample can be:
enum e { zero = decltype(delete static_cast<e*>(nullptr), 0){} };
which is currently rejected by Clang since C++26 mode (Godbolt link).
Note that UB can never be raised from such a delete-expression, because the enumerator must be a constant. However, given such delete-expressions are weird and useless, and there's already an implementation rejecting them, it may be better to make them ill-formed.
Also "the object being deleted" in the current wording is a bit unclear, because the value of the operand still seems to matter after P3144R2, while the intent is probably that only the type of the operand is concerned.
Suggested resolution:
Change [expr.delete] p4 as indicated:
If the
object being deleted has incomplete class typeoperand is of type “pointer to incompletely-defined object type” at the point of deletion, the program is ill-formed.
[Drafting note: A function pointer or pointer to cv void
is already rejected in [expr.delete] p1 via CWG599.]