Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / depr / exception.unexpected / set.unexpected / get_unexpected.pass.cpp
blobd39b9fd3caa52e9e57fecf60eb2c1f6abae3743e
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: c++03 || c++11 || c++14
11 // test get_unexpected
13 #include <exception>
14 #include <cassert>
15 #include <cstdlib>
17 #include "test_macros.h"
19 void f1() {}
20 void f2() {}
22 void f3()
24 std::exit(0);
27 int main(int, char**)
30 std::unexpected_handler old = std::get_unexpected();
31 // verify there is a previous unexpected handler
32 assert(old);
33 std::set_unexpected(f1);
34 assert(std::get_unexpected() == f1);
35 // verify f1 was replace with f2
36 std::set_unexpected(f2);
37 assert(std::get_unexpected() == f2);
38 // verify calling original unexpected handler calls terminate
39 std::set_terminate(f3);
40 (*old)();
41 assert(0);
43 return 0;