treat that as an implicit delete-expression. This is also called for
the delete if the constructor throws in a new-expression, and for a
deleting destructor (which implements a delete-expression). */
+ /* But leave this flag off for destroying delete to avoid wrong
+ assumptions in the optimizers. */
tree call = extract_call_expr (ret);
- if (TREE_CODE (call) == CALL_EXPR)
+ if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn))
CALL_FROM_NEW_OR_DELETE_P (call) = 1;
return ret;
complain);
}
- if (!destroying_delete && type_build_dtor_call (type))
+ if (destroying_delete)
+ /* The operator delete will call the destructor. */
+ expr = addr;
+ else if (type_build_dtor_call (type))
expr = build_dtor_call (cp_build_fold_indirect_ref (addr),
auto_delete, flags, complain);
else
--- /dev/null
+// PR c++/91859
+// { dg-do run { target c++20 } }
+// { dg-additional-options -O2 }
+
+#include <cstdlib>
+#include <new>
+
+struct Expression {
+ int i = 0;
+ void *operator new(std::size_t);
+ void operator delete(Expression *, std::destroying_delete_t);
+};
+
+void * Expression::operator new(std::size_t sz)
+{
+ return std::malloc(sz);
+}
+
+int i;
+
+void Expression::operator delete(Expression *p, std::destroying_delete_t)
+{
+ Expression * e = p;
+ ::i = e->i;
+ p->~Expression();
+ std::free(p);
+}
+
+int main()
+{
+ auto p = new Expression();
+ p->i = 1;
+ delete p;
+ if (i != 1)
+ __builtin_abort();
+}
/* In a CALL_EXPR, if the function being called is DECL_IS_OPERATOR_NEW_P or
DECL_IS_OPERATOR_DELETE_P, true for allocator calls from C++ new or delete
- expressions. */
+ expressions. Not set for C++20 destroying delete operators. */
#define CALL_FROM_NEW_OR_DELETE_P(NODE) \
(CALL_EXPR_CHECK (NODE)->base.protected_flag)