Marshall Clow | 8731c5d | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 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 | |
Marshall Clow | 8731c5d | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 10 | // test uncaught_exceptions |
| 11 | |
| 12 | #include <exception> |
| 13 | #include <cassert> |
| 14 | |
| 15 | struct A |
| 16 | { |
| 17 | ~A() |
| 18 | { |
| 19 | assert(std::uncaught_exceptions() > 0); |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | struct B |
| 24 | { |
| 25 | B() |
| 26 | { |
| 27 | // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475 |
| 28 | assert(std::uncaught_exceptions() == 0); |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | try |
| 35 | { |
| 36 | A a; |
| 37 | assert(std::uncaught_exceptions() == 0); |
| 38 | throw B(); |
| 39 | } |
| 40 | catch (...) |
| 41 | { |
| 42 | assert(std::uncaught_exception() == 0); |
| 43 | } |
| 44 | assert(std::uncaught_exceptions() == 0); |
| 45 | } |