aboutsummaryrefslogtreecommitdiff
path: root/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp
blob: b9267158802708b3de88bddbbe93f220ac8bc649 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//===----------------------------------------------------------------------===//
//
//                     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: libcpp-no-exceptions
// test uncaught_exceptions

#include <exception>
#include <cassert>

struct A
{
    ~A()
    {
        assert(std::uncaught_exceptions() > 0);
    }
};

struct B
{
    B()
    {
        // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475
        assert(std::uncaught_exceptions() == 0);
    }
};

int main()
{
    try
    {
        A a;
        assert(std::uncaught_exceptions() == 0);
        throw B();
    }
    catch (...)
    {
        assert(std::uncaught_exception() == 0);
    }
    assert(std::uncaught_exceptions() == 0);
}