1 // Test for noexcept-specification 2 // { dg-do compile { target c++11 } } 3 4 #define SA(X) static_assert(X, #X) 5 6 void f(); 7 void f() noexcept(false); 8 void f() noexcept(1 == 0); 9 void f(); 10 11 SA(!noexcept(f())); 12 13 void g() throw (int); // { dg-message "previous declaration" "" { target { ! c++17 } } } 14 // { dg-error "dynamic exception specification" "" { target c++17 } .-1 } 15 // { dg-warning "deprecated" "" { target { ! c++17 } } .-2 } 16 void g() noexcept(false); // { dg-error "different exception" "" { target { ! c++17 } } } 17 void g(); 18 19 void h() throw(); 20 void h() noexcept; 21 void h() throw(); 22 void h() noexcept; 23 24 template <class T> 25 void g (T) noexcept(noexcept(T())); // { dg-message "previous declaration" } 26 template <class T> 27 void g (T) noexcept(noexcept(T(0))); // { dg-error "different exception" } 28 29 template <class T> 30 void f (T) noexcept(noexcept(T()) && noexcept(T())); 31 template <class T> 32 void f (T) noexcept(noexcept(T()) && noexcept(T())); 33 template <class T> 34 void f2(T a) noexcept (noexcept (f (a))); 35 36 struct A { A(); }; 37 SA(noexcept(f(1))); 38 SA(!noexcept(f(A()))); 39 SA(noexcept(f2(1))); 40 SA(!noexcept(f2(A()))); 41 42 template <class... Ts> 43 void f3(Ts... ts) noexcept (noexcept (f(ts...))); 44 45 SA(noexcept(f3(1))); 46 SA(!noexcept(f3(A()))); 47 48 template <class T1, class T2> 49 void f (T1, T2) noexcept(noexcept(T1(), T2())); 50 51 struct B { }; 52 53 SA(noexcept(f3(1,B()))); 54 SA(!noexcept(f3(1,A()))); 55 SA(!noexcept(f3(A(),1))); 56 SA(!noexcept(f3(A(),A()))); 57