1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // REQUIRES: c++98 || c++03 || c++11 || c++14 11 12 // test set_unexpected 13 14 #include <exception> 15 #include <cassert> 16 #include <cstdlib> 17 f1()18void f1() {} f2()19void f2() {} 20 f3()21void f3() 22 { 23 std::exit(0); 24 } 25 main()26int main() 27 { 28 std::unexpected_handler old = std::set_unexpected(f1); 29 // verify there is a previous unexpected handler 30 assert(old); 31 // verify f1 was replace with f2 32 assert(std::set_unexpected(f2) == f1); 33 // verify calling original unexpected handler calls terminate 34 std::set_terminate(f3); 35 (*old)(); 36 assert(0); 37 } 38