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