[Bug libstdc++/68210] nothrow operator fails to call default new
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Aug 10 19:30:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68210
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |9.0
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #0)
> assert (0 == p);
> assert (2 == new_handler_called);
> assert (bad_alloc_thrown);
I think this test case is wrong. The new handler is set, so we never get to:
else {
bad_alloc_thrown = true;
throw MyBadAlloc ();
}
So bad_alloc_throw is never set.
I'm using this instead, which passes with my fixed libstdc++ and with libc++:
int main ()
{
new_called = 0;
void *p = operator new (1, std::nothrow);
VERIFY (p != 0);
VERIFY (1 == new_called);
std::set_new_handler (new_handler);
new_fail = true;
try {
p = operator new (1, std::nothrow);
}
catch (...) {
VERIFY (!"nothrow operator new threw");
}
VERIFY (0 == p);
VERIFY (2 == new_handler_called);
VERIFY (!bad_alloc_thrown);
std::set_new_handler (0);
new_fail = true;
new_handler_called = 0;
try {
p = operator new (1, std::nothrow);
}
catch (...) {
VERIFY (!"nothrow operator new threw");
}
VERIFY (0 == p);
VERIFY (0 == new_handler_called);
VERIFY (bad_alloc_thrown);
}
More information about the Gcc-bugs
mailing list