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 // test set_unexpected 11 12 #include <exception> 13 #include <cassert> 14 #include <cstdlib> 15 f1()16void f1() {} f2()17void f2() {} 18 f3()19void f3() 20 { 21 std::exit(0); 22 } 23 main()24int main() 25 { 26 std::unexpected_handler old = std::set_unexpected(f1); 27 // verify there is a previous unexpected handler 28 assert(old); 29 // verify f1 was replace with f2 30 assert(std::set_unexpected(f2) == f1); 31 // verify calling original unexpected handler calls terminate 32 std::set_terminate(f3); 33 #if !defined(__ANDROID__) 34 // Disable the following for Android whoes __gabixx::__default_terminate() 35 // causes segfault on purpose to get stack dump 36 (*old)(); 37 assert(0); 38 #endif 39 } 40