fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <iostream>
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11. template<typename T >
  12. void operator delete(void*, T*& p)
  13. {
  14. delete p;
  15. p = nullptr;
  16. }
  17. struct A{
  18. ~A(){ puts(__PRETTY_FUNCTION__);}
  19. };
  20. struct B{
  21. A* p;
  22. B() : p(new A) {}
  23. ~B(){operator delete(p,p);}
  24. void release()
  25. { operator delete(p, p); throw 123;}
  26. };
  27.  
  28. int main()
  29. {
  30. try{
  31. B b;
  32. b.release();
  33. } catch(...){
  34. puts("caught");
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5320KB
stdin
45
stdout
A::~A()
caught