Marshall Clow | 5013d7c | 2015-06-02 13:03:17 +0000 | [diff] [blame] | 1 | //===------------------- uncaught_exceptions.pass.cpp ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: libcxxabi-no-exceptions |
| 11 | |
Marshall Clow | 5013d7c | 2015-06-02 13:03:17 +0000 | [diff] [blame] | 12 | #include <cxxabi.h> |
| 13 | #include <exception> |
| 14 | #include <cassert> |
| 15 | |
| 16 | // namespace __cxxabiv1 { |
| 17 | // extern bool __cxa_uncaught_exception () throw(); |
| 18 | // extern unsigned int __cxa_uncaught_exceptions() throw(); |
| 19 | // } |
| 20 | |
| 21 | struct A { |
| 22 | ~A() { assert( __cxxabiv1::__cxa_uncaught_exception()); } |
| 23 | }; |
| 24 | |
| 25 | struct B { |
Eric Fiselier | f0c4e60 | 2016-12-11 05:43:20 +0000 | [diff] [blame] | 26 | B(unsigned cnt) : data_(cnt) {} |
Marshall Clow | 5013d7c | 2015-06-02 13:03:17 +0000 | [diff] [blame] | 27 | ~B() { assert( data_ == __cxxabiv1::__cxa_uncaught_exceptions()); } |
Eric Fiselier | f0c4e60 | 2016-12-11 05:43:20 +0000 | [diff] [blame] | 28 | unsigned data_; |
Marshall Clow | 5013d7c | 2015-06-02 13:03:17 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | int main () |
| 32 | { |
| 33 | try { A a; throw 3; assert (false); } |
| 34 | catch (int) {} |
| 35 | |
| 36 | try { B b(1); throw 3; assert (false); } |
| 37 | catch (int) {} |
| 38 | } |