在 2023/5/4 18:12, Jonathan Wakely via Gcc-help 写道:
The C++ standard is clear, see [expr.delete] p4: "The cast-expression in a delete-expression shall be evaluated exactly once." That wording has been present since C++98. Please file a bug.
The issue here about C++ standard is that nothing says the operand of a delete-expression shall be a prvalue [1] [2].
It looks to me that, if its operand is an lvalue, the lvalue-to-rvalue conversion of the operand, necessary for calling the destructor and deallocation function, may occur twice, because it's not part of the delete-expression. So my opinion is that, although GCC behavior is a little unexpected, it's reasonable and such code should be avoided.
But [expr.delete]-7 doesn't seem to allow this anyway... [1] https://cplusplus.github.io/CWG/issues/1642.html [2] https://cplusplus.github.io/CWG/issues/2728.html -- Best regards, LIU Hao
Attachment:
OpenPGP_signature
Description: OpenPGP digital signature