1 // Runtime test for noexcept-specification.
2 // { dg-options "-std=c++0x -Wnoexcept" }
3 // { dg-do run { target nonpic } }
4 
5 #include <exception>
6 #include <cstdlib>
7 
my_terminate()8 void my_terminate ()
9 {
10   std::exit (0);
11 }
12 
my_unexpected()13 void my_unexpected ()
14 {
15   throw;
16 }
17 
g()18 void g() { throw 1; }
19 void (*p)() = g;
f()20 void f () noexcept (false)
21 {
22   p();
23 }
24 
25 template <class T>
f(T)26 void f(T) noexcept (noexcept (T())) // { dg-warning "false" }
27 {
28   p();
29 }
30 
31 template <class T>
f2(T a)32 void f2(T a) noexcept (noexcept (f (a)))
33 {
34   f(a);
35 }
36 
AA37 struct A { A() { } };		// { dg-warning "does not throw" }
38 
main()39 int main()
40 {
41   // noexcept(false) allows throw.
42   try { f(); } catch (int) { }
43   // noexcept(noexcept(A())) == noexcept(false).
44   try { f(A()); } catch (int) { }
45   try { f2(A()); } catch (int) { }
46 
47   std::set_terminate (my_terminate);
48   // noexcept(noexcept(int())) == noexcept(true).
49   try { f2(1); } catch (...) { }
50   return 1;
51 }
52