Stefan Strasser wrote:
why is delete an expression and not a statement? (in my draft copy of
the standard).
All expressions can be turned into a statement by
appending a semicolon. (There are also other types of
statement).
I was about to ask the same question about "throw" but found an
expression case of throw("return boolvalue ? 5 : throw 5;").
but "delete" neither does exit the scope nor has a return value.
'delete' is actually an operator. It is a unary operator (takes
one argument) and evaluates to a type of 'void'.
Cf. the unary operator 'sizeof' which takes one argument and evaulates
to a type of 'size_t'. Also cf. the unary operator '-' which
evaluates to the type of its argument. Don't be confused by the
fact that some operators have alphabetical names, and some don'.
Any use of an operator with valid operands, is an expression.
I think it is simpler for the C++ grammar to add 'delete' in
along with the other unary operators, rather than to define
a new type of statement especially for 'delete'.
Interestingly, we can have this valid but bizarre code:
void foo()
{
char *p = boo();
if (bar())
return delete p;
baz(p);
}