1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
17 #include "test_macros.h"
20 virtual void foo() {};
23 class Derived
: public Base
{};
25 Derived
&test_bad_cast(Base
& b
) {
26 return dynamic_cast<Derived
&>(b
);
31 void my_terminate() { exit(0); }
35 // swap-out the terminate handler
36 void (*default_handler
)() = std::get_terminate();
37 std::set_terminate(my_terminate
);
39 #ifndef TEST_HAS_NO_EXCEPTIONS
42 Derived
&d
= test_bad_cast(gB
);
45 #ifndef TEST_HAS_NO_EXCEPTIONS
46 } catch (std::bad_cast
const&) {
54 // failure, restore the default terminate handler and fire
55 std::set_terminate(default_handler
);