| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //===----------------------- cxa_bad_cast.pass.cpp ------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++98, c++03 | ||
|
|
||
| #include <cxxabi.h> | ||
| #include <cassert> | ||
| #include <stdlib.h> | ||
| #include <exception> | ||
| #include <typeinfo> | ||
|
|
||
| class Base { | ||
| virtual void foo() {}; | ||
| }; | ||
|
|
||
| class Derived : public Base {}; | ||
|
|
||
| Derived &test_bad_cast(Base b) { | ||
| return dynamic_cast<Derived&>(b); | ||
| } | ||
|
|
||
| Base gB; | ||
|
|
||
| void my_terminate() { exit(0); } | ||
|
|
||
| int main () | ||
| { | ||
| // swap-out the terminate handler | ||
| void (*default_handler)() = std::get_terminate(); | ||
| std::set_terminate(my_terminate); | ||
|
|
||
| #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | ||
| try { | ||
| #endif | ||
| Derived &d = test_bad_cast(gB); | ||
| assert(false); | ||
| #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | ||
| } catch (std::bad_cast) { | ||
| // success | ||
| return 0; | ||
| } catch (...) { | ||
| assert(false); | ||
| } | ||
| #endif | ||
|
|
||
| // failure, restore the default terminate handler and fire | ||
| std::set_terminate(default_handler); | ||
| std::terminate(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //===----------------------- cxa_bad_typeid.pass.cpp ------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===------------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++98, c++03 | ||
|
|
||
| #include <cxxabi.h> | ||
| #include <cassert> | ||
| #include <stdlib.h> | ||
| #include <exception> | ||
| #include <typeinfo> | ||
| #include <string> | ||
| #include <iostream> | ||
|
|
||
| class Base { | ||
| virtual void foo() {}; | ||
| }; | ||
|
|
||
| class Derived : public Base {}; | ||
|
|
||
| std::string test_bad_typeid(Derived *p) { | ||
| typeid(*p).name(); | ||
| } | ||
|
|
||
| void my_terminate() { std::cout << "A" << std::endl; exit(0); } | ||
|
|
||
| int main () | ||
| { | ||
| // swap-out the terminate handler | ||
| void (*default_handler)() = std::get_terminate(); | ||
| std::set_terminate(my_terminate); | ||
|
|
||
| #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | ||
| try { | ||
| #endif | ||
| test_bad_typeid(nullptr); | ||
| assert(false); | ||
| #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS | ||
| } catch (std::bad_typeid) { | ||
| // success | ||
| return 0; | ||
| } catch (...) { | ||
| assert(false); | ||
| } | ||
| #endif | ||
|
|
||
| // failure, restore the default terminate handler and fire | ||
| std::set_terminate(default_handler); | ||
| std::terminate(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //===----------------------- noexception1.pass.cpp ------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++98, c++03 | ||
| // REQUIRES: libcxxabi-no-exceptions | ||
|
|
||
| #include <cxxabi.h> | ||
| #include <exception> | ||
| #include <cassert> | ||
| #include <stdlib.h> | ||
|
|
||
| // namespace __cxxabiv1 { | ||
| // void __cxa_increment_exception_refcount(void *thrown_object) throw(); | ||
| // } | ||
|
|
||
| unsigned gCounter = 0; | ||
|
|
||
| void my_terminate() { exit(0); } | ||
|
|
||
| int main () | ||
| { | ||
| // should not call std::terminate() | ||
| __cxxabiv1::__cxa_increment_exception_refcount(nullptr); | ||
|
|
||
| std::set_terminate(my_terminate); | ||
|
|
||
| // should call std::terminate() | ||
| __cxxabiv1::__cxa_increment_exception_refcount((void*) &gCounter); | ||
| assert(false); | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //===----------------------- noexception2.pass.cpp ------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++98, c++03 | ||
| // REQUIRES: libcxxabi-no-exceptions | ||
|
|
||
| #include <cxxabi.h> | ||
| #include <exception> | ||
| #include <cassert> | ||
| #include <stdlib.h> | ||
|
|
||
| // namespace __cxxabiv1 { | ||
| // void __cxa_decrement_exception_refcount(void *thrown_object) throw(); | ||
| // } | ||
|
|
||
| unsigned gCounter = 0; | ||
|
|
||
| void my_terminate() { exit(0); } | ||
|
|
||
| int main () | ||
| { | ||
| // should not call std::terminate() | ||
| __cxxabiv1::__cxa_decrement_exception_refcount(nullptr); | ||
|
|
||
| std::set_terminate(my_terminate); | ||
|
|
||
| // should call std::terminate() | ||
| __cxxabiv1::__cxa_decrement_exception_refcount((void*) &gCounter); | ||
| assert(false); | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //===----------------------- noexception3.pass.cpp ------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++98, c++03 | ||
| // REQUIRES: libcxxabi-no-exceptions | ||
|
|
||
| #include <cxxabi.h> | ||
| #include <exception> | ||
| #include <cassert> | ||
| #include <stdlib.h> | ||
|
|
||
| // namespace __cxxabiv1 { | ||
| // void __cxa_rethrow_primary_exception(void* thrown_object); | ||
| // } | ||
|
|
||
| unsigned gCounter = 0; | ||
|
|
||
| void my_terminate() { exit(0); } | ||
|
|
||
| int main () | ||
| { | ||
| // should not call std::terminate() | ||
| __cxxabiv1::__cxa_rethrow_primary_exception(nullptr); | ||
|
|
||
| std::set_terminate(my_terminate); | ||
|
|
||
| // should call std::terminate() | ||
| __cxxabiv1::__cxa_rethrow_primary_exception((void*) &gCounter); | ||
| assert(false); | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //===----------------------- noexception4.pass.cpp ------------------------===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is dual licensed under the MIT and the University of Illinois Open | ||
| // Source Licenses. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: libcxxabi-no-exceptions | ||
|
|
||
| #include <cxxabi.h> | ||
| #include <exception> | ||
| #include <cassert> | ||
|
|
||
| // namespace __cxxabiv1 { | ||
| // void *__cxa_current_primary_exception() throw(); | ||
| // extern bool __cxa_uncaught_exception () throw(); | ||
| // extern unsigned int __cxa_uncaught_exceptions() throw(); | ||
| // } | ||
|
|
||
| int main () | ||
| { | ||
| // Trivially | ||
| assert(nullptr == __cxxabiv1::__cxa_current_primary_exception()); | ||
| assert(!__cxxabiv1::__cxa_uncaught_exception()); | ||
| assert(0 == __cxxabiv1::__cxa_uncaught_exceptions()); | ||
| return 0; | ||
| } |