blob: 22d8d8e982ae6780990663e46c7350745bd09579 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// test uncaught_exception
11
12#include <exception>
13#include <cassert>
14
15struct A
16{
17 ~A()
18 {
19 assert(std::uncaught_exception());
20 }
21};
22
Nick Kledzik770a3c52011-03-11 22:33:07 +000023struct B
24{
Howard Hinnant171771a2013-07-08 21:06:38 +000025 B()
26 {
27 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475
Nick Kledzik770a3c52011-03-11 22:33:07 +000028 assert(!std::uncaught_exception());
Howard Hinnant171771a2013-07-08 21:06:38 +000029 }
Nick Kledzik770a3c52011-03-11 22:33:07 +000030};
31
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032int main()
33{
34 try
35 {
36 A a;
37 assert(!std::uncaught_exception());
Nick Kledzik770a3c52011-03-11 22:33:07 +000038 throw B();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039 }
40 catch (...)
41 {
42 assert(!std::uncaught_exception());
43 }
44 assert(!std::uncaught_exception());
45}