xref: /aosp_15_r20/external/libcxxabi/test/uncaught_exceptions.pass.cpp (revision c05d8e5dc3e10f6ce4317e8bc22cc4a25f55fa94)
1*c05d8e5dSAndroid Build Coastguard Worker //===------------------- uncaught_exceptions.pass.cpp ---------------------===//
2*c05d8e5dSAndroid Build Coastguard Worker //
3*c05d8e5dSAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*c05d8e5dSAndroid Build Coastguard Worker //
5*c05d8e5dSAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*c05d8e5dSAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*c05d8e5dSAndroid Build Coastguard Worker //
8*c05d8e5dSAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*c05d8e5dSAndroid Build Coastguard Worker 
10*c05d8e5dSAndroid Build Coastguard Worker // UNSUPPORTED: libcxxabi-no-exceptions
11*c05d8e5dSAndroid Build Coastguard Worker 
12*c05d8e5dSAndroid Build Coastguard Worker #include <cxxabi.h>
13*c05d8e5dSAndroid Build Coastguard Worker #include <exception>
14*c05d8e5dSAndroid Build Coastguard Worker #include <cassert>
15*c05d8e5dSAndroid Build Coastguard Worker 
16*c05d8e5dSAndroid Build Coastguard Worker // namespace __cxxabiv1 {
17*c05d8e5dSAndroid Build Coastguard Worker //      extern bool          __cxa_uncaught_exception () throw();
18*c05d8e5dSAndroid Build Coastguard Worker //      extern unsigned int  __cxa_uncaught_exceptions() throw();
19*c05d8e5dSAndroid Build Coastguard Worker // }
20*c05d8e5dSAndroid Build Coastguard Worker 
21*c05d8e5dSAndroid Build Coastguard Worker struct A {
~AA22*c05d8e5dSAndroid Build Coastguard Worker     ~A() { assert( __cxxabiv1::__cxa_uncaught_exception()); }
23*c05d8e5dSAndroid Build Coastguard Worker     };
24*c05d8e5dSAndroid Build Coastguard Worker 
25*c05d8e5dSAndroid Build Coastguard Worker struct B {
BB26*c05d8e5dSAndroid Build Coastguard Worker     B(unsigned cnt) : data_(cnt) {}
~BB27*c05d8e5dSAndroid Build Coastguard Worker     ~B() { assert( data_ == __cxxabiv1::__cxa_uncaught_exceptions()); }
28*c05d8e5dSAndroid Build Coastguard Worker     unsigned data_;
29*c05d8e5dSAndroid Build Coastguard Worker     };
30*c05d8e5dSAndroid Build Coastguard Worker 
main()31*c05d8e5dSAndroid Build Coastguard Worker int main ()
32*c05d8e5dSAndroid Build Coastguard Worker {
33*c05d8e5dSAndroid Build Coastguard Worker     try { A a; throw 3; assert (false); }
34*c05d8e5dSAndroid Build Coastguard Worker     catch (int) {}
35*c05d8e5dSAndroid Build Coastguard Worker 
36*c05d8e5dSAndroid Build Coastguard Worker     try { B b(1); throw 3; assert (false); }
37*c05d8e5dSAndroid Build Coastguard Worker     catch (int) {}
38*c05d8e5dSAndroid Build Coastguard Worker }
39