1 // { dg-do run } 2 // Origin: philip_martin@ntlworld.com 3 4 #include <new> 5 6 extern "C" void abort(); 7 8 bool new_flag = false; 9 bool delete_flag = false; 10 11 struct X { XX12 X() 13 { 14 throw 1; 15 } newX16 void* operator new ( std::size_t n ) 17 #if __cplusplus <= 201402L 18 throw ( std::bad_alloc ) // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } } 19 #endif 20 { 21 new_flag = true; 22 return ::operator new( n ); 23 } deleteX24 void operator delete( void* p, std::size_t n ) throw() 25 { 26 delete_flag = true; 27 ::operator delete( p ); 28 } 29 }; 30 31 int main()32main() 33 { 34 try 35 { 36 X* x = new X; // gcc 3.0 fails to call operator delete when X::X throws 37 } 38 catch ( ... ) 39 { 40 } 41 if ( ! new_flag || ! delete_flag ) 42 ::abort(); 43 } 44