With new (nothrow) we need to check whether the allocation returned null,
and the resulting COND_EXPR was confusing -Wmismatched-new-delete-2 at -O0.
Let's help it out by appending the address if it's the same on both arms.
gcc/cp/ChangeLog:
* init.cc (build_new_1): Append alloc_node to checking COND_EXPR.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wmismatched-new-delete-2.C: Remove xfail.
complain);
rval = build_conditional_expr (input_location, ifexp, rval,
alloc_node, complain);
+ /* If there's no offset between data_addr and alloc_node, append it
+ to help -Wmismatched-new-delete at -O0. */
+ if (!cookie_size)
+ rval = build2 (COMPOUND_EXPR, TREE_TYPE (alloc_node),
+ rval, alloc_node);
}
/* Perform the allocation before anything else, so that ALLOC_NODE
delete p; // { dg-warning "'static void X1::operator delete\\(void\\*\\)' called on pointer returned from a mismatched allocation function" }
}
{
- // The following requires optimization (see warn_x1_array_mismatch()).
X1 *p = new (std::nothrow) X1[3];
- delete p; // { dg-warning "'static void X1::operator delete\\(void\\*\\)' called on pointer returned from a mismatched allocation function" "pr?????" { xfail *-*-* } }
+ delete p; // { dg-warning "'static void X1::operator delete\\(void\\*\\)' called on pointer returned from a mismatched allocation function" }
}
}