#include <new>
#include <iostream>
#include <cstdlib>
struct allocator {};
void *operator new(std::size_t size, allocator&) {
if(void *ptr = std::malloc(size)) {
return ptr;
}
throw std::bad_alloc();
}
void operator delete(void *ptr) {
std::cout << "deleting\n";
std::free(ptr);
}
struct s {
s() {
throw "failed";
}
};
int main() {
allocator a;
try {
new (a) s;
} catch(...) {
std::cout << "catching\n";
}
}
I2luY2x1ZGUgPG5ldz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KCnN0cnVjdCBhbGxvY2F0b3Ige307Cgp2b2lkICpvcGVyYXRvciBuZXcoc3RkOjpzaXplX3Qgc2l6ZSwgYWxsb2NhdG9yJikgewogICAgaWYodm9pZCAqcHRyID0gc3RkOjptYWxsb2Moc2l6ZSkpIHsKICAgICAgICByZXR1cm4gcHRyOwogICAgfQogICAgdGhyb3cgc3RkOjpiYWRfYWxsb2MoKTsKfQoKdm9pZCBvcGVyYXRvciBkZWxldGUodm9pZCAqcHRyKSB7CiAgICBzdGQ6OmNvdXQgPDwgImRlbGV0aW5nXG4iOwogICAgc3RkOjpmcmVlKHB0cik7Cn0KCnN0cnVjdCBzIHsKICAgIHMoKSB7CiAgICAgICAgdGhyb3cgImZhaWxlZCI7CiAgICB9Cn07CgppbnQgbWFpbigpIHsKICAgIGFsbG9jYXRvciBhOwoKICAgIHRyeSB7CiAgICAgICAgbmV3IChhKSBzOwogICAgfSBjYXRjaCguLi4pIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgImNhdGNoaW5nXG4iOwogICAgfQp9Cg==