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()16 void f1() {}
f2()17 void f2() {}
18 
f3()19 void f3()
20 {
21     std::exit(0);
22 }
23 
main()24 int 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     (*old)();
34     assert(0);
35 }
36