• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 get_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 
27     std::unexpected_handler old = std::get_unexpected();
28     // verify there is a previous unexpected handler
29     assert(old);
30     std::set_unexpected(f1);
31     assert(std::get_unexpected() == f1);
32     // verify f1 was replace with f2
33     std::set_unexpected(f2);
34     assert(std::get_unexpected() == f2);
35     // verify calling original unexpected handler calls terminate
36     std::set_terminate(f3);
37     (*old)();
38     assert(0);
39 }
40