1*67e74705SXin Li // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s 2*67e74705SXin Li 3*67e74705SXin Li // Simple parser tests, dynamic specification. 4*67e74705SXin Li 5*67e74705SXin Li namespace dyn { 6*67e74705SXin Li 7*67e74705SXin Li struct X { }; 8*67e74705SXin Li 9*67e74705SXin Li struct Y { }; 10*67e74705SXin Li f()11*67e74705SXin Li void f() throw() { } 12*67e74705SXin Li g(int)13*67e74705SXin Li void g(int) throw(X) { } 14*67e74705SXin Li h()15*67e74705SXin Li void h() throw(X, Y) { } 16*67e74705SXin Li 17*67e74705SXin Li class Class { foo()18*67e74705SXin Li void foo() throw (X, Y) { } 19*67e74705SXin Li }; 20*67e74705SXin Li 21*67e74705SXin Li void (*fptr)() throw(); 22*67e74705SXin Li 23*67e74705SXin Li } 24*67e74705SXin Li 25*67e74705SXin Li // Simple parser tests, noexcept specification. 26*67e74705SXin Li 27*67e74705SXin Li namespace noex { 28*67e74705SXin Li f1()29*67e74705SXin Li void f1() noexcept { } f2()30*67e74705SXin Li void f2() noexcept (true) { } f3()31*67e74705SXin Li void f3() noexcept (false) { } f4()32*67e74705SXin Li void f4() noexcept (1 < 2) { } 33*67e74705SXin Li 34*67e74705SXin Li class CA1 { foo()35*67e74705SXin Li void foo() noexcept { } bar()36*67e74705SXin Li void bar() noexcept (true) { } 37*67e74705SXin Li }; 38*67e74705SXin Li 39*67e74705SXin Li void (*fptr1)() noexcept; 40*67e74705SXin Li void (*fptr2)() noexcept (true); 41*67e74705SXin Li 42*67e74705SXin Li } 43*67e74705SXin Li 44*67e74705SXin Li namespace mix { 45*67e74705SXin Li f()46*67e74705SXin Li void f() throw(int) noexcept { } // expected-error {{cannot have both}} g()47*67e74705SXin Li void g() noexcept throw(int) { } // expected-error {{cannot have both}} 48*67e74705SXin Li 49*67e74705SXin Li } 50*67e74705SXin Li 51*67e74705SXin Li // Sema tests, noexcept specification 52*67e74705SXin Li 53*67e74705SXin Li namespace noex { 54*67e74705SXin Li 55*67e74705SXin Li struct A {}; 56*67e74705SXin Li 57*67e74705SXin Li void g1() noexcept(A()); // expected-error {{not contextually convertible}} 58*67e74705SXin Li void g2(bool b) noexcept(b); // expected-error {{argument to noexcept specifier must be a constant expression}} expected-note {{read of non-const variable 'b'}} expected-note {{here}} 59*67e74705SXin Li 60*67e74705SXin Li } 61*67e74705SXin Li 62*67e74705SXin Li namespace noexcept_unevaluated { f(T)63*67e74705SXin Li template<typename T> bool f(T) { 64*67e74705SXin Li T* x = 1; 65*67e74705SXin Li } 66*67e74705SXin Li 67*67e74705SXin Li template<typename T> g(T x)68*67e74705SXin Li void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { } 69*67e74705SXin Li h()70*67e74705SXin Li void h() { 71*67e74705SXin Li g(1); 72*67e74705SXin Li } 73*67e74705SXin Li } 74*67e74705SXin Li 75*67e74705SXin Li namespace PR11084 { 76*67e74705SXin Li template<int X> struct A { fPR11084::A77*67e74705SXin Li static int f() noexcept(1/X) { return 10; } // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}} 78*67e74705SXin Li }; 79*67e74705SXin Li f()80*67e74705SXin Li template<int X> void f() { 81*67e74705SXin Li int (*p)() noexcept(1/X); // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}} 82*67e74705SXin Li }; 83*67e74705SXin Li g()84*67e74705SXin Li void g() { 85*67e74705SXin Li A<0>::f(); // expected-note{{in instantiation of exception specification for 'f'}} 86*67e74705SXin Li f<0>(); // expected-note{{in instantiation of function template specialization}} 87*67e74705SXin Li } 88*67e74705SXin Li } 89