• 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 // REQUIRES: c++98 || c++03 || c++11 || c++14
11 
12 // test get_unexpected
13 
14 #include <exception>
15 #include <cassert>
16 #include <cstdlib>
17 
f1()18 void f1() {}
f2()19 void f2() {}
20 
f3()21 void f3()
22 {
23     std::exit(0);
24 }
25 
main()26 int main()
27 {
28 
29     std::unexpected_handler old = std::get_unexpected();
30     // verify there is a previous unexpected handler
31     assert(old);
32     std::set_unexpected(f1);
33     assert(std::get_unexpected() == f1);
34     // verify f1 was replace with f2
35     std::set_unexpected(f2);
36     assert(std::get_unexpected() == f2);
37     // verify calling original unexpected handler calls terminate
38     std::set_terminate(f3);
39     (*old)();
40     assert(0);
41 }
42