Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / test / cxa_bad_typeid.pass.cpp
blobd5d7b3413ff10637ea92194a393efed4712f07fc
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 // UNSUPPORTED: c++03
11 #include <cxxabi.h>
12 #include <cassert>
13 #include <stdlib.h>
14 #include <exception>
15 #include <typeinfo>
16 #include <string>
18 #include "test_macros.h"
20 class Base {
21 virtual void foo() {};
24 class Derived : public Base {};
26 std::string test_bad_typeid(Derived *p) {
27 return typeid(*p).name();
30 void my_terminate() { exit(0); }
32 int main ()
34 // swap-out the terminate handler
35 void (*default_handler)() = std::get_terminate();
36 std::set_terminate(my_terminate);
38 #ifndef TEST_HAS_NO_EXCEPTIONS
39 try {
40 #endif
41 test_bad_typeid(nullptr);
42 assert(false);
43 #ifndef TEST_HAS_NO_EXCEPTIONS
44 } catch (std::bad_typeid const&) {
45 // success
46 return 0;
47 } catch (...) {
48 assert(false);
50 #endif
52 // failure, restore the default terminate handler and fire
53 std::set_terminate(default_handler);
54 std::terminate();