19ca5c425SRichard Smith // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
2965b0e31SSebastian Redl 
3965b0e31SSebastian Redl // Simple parser tests, dynamic specification.
4965b0e31SSebastian Redl 
5965b0e31SSebastian Redl namespace dyn {
6965b0e31SSebastian Redl 
7965b0e31SSebastian Redl   struct X { };
8965b0e31SSebastian Redl 
9965b0e31SSebastian Redl   struct Y { };
10965b0e31SSebastian Redl 
f()11965b0e31SSebastian Redl   void f() throw() { }
12965b0e31SSebastian Redl 
g(int)13965b0e31SSebastian Redl   void g(int) throw(X) { }
14965b0e31SSebastian Redl 
h()15965b0e31SSebastian Redl   void h() throw(X, Y) { }
16965b0e31SSebastian Redl 
17965b0e31SSebastian Redl   class Class {
foo()18965b0e31SSebastian Redl     void foo() throw (X, Y) { }
19965b0e31SSebastian Redl   };
20965b0e31SSebastian Redl 
21965b0e31SSebastian Redl   void (*fptr)() throw();
22965b0e31SSebastian Redl 
23965b0e31SSebastian Redl }
24965b0e31SSebastian Redl 
25965b0e31SSebastian Redl // Simple parser tests, noexcept specification.
26965b0e31SSebastian Redl 
27965b0e31SSebastian Redl namespace noex {
28965b0e31SSebastian Redl 
f1()29fa453cfdSSebastian Redl   void f1() noexcept { }
f2()30fa453cfdSSebastian Redl   void f2() noexcept (true) { }
f3()31fa453cfdSSebastian Redl   void f3() noexcept (false) { }
f4()32fa453cfdSSebastian Redl   void f4() noexcept (1 < 2) { }
33965b0e31SSebastian Redl 
34fa453cfdSSebastian Redl   class CA1 {
foo()35965b0e31SSebastian Redl     void foo() noexcept { }
bar()36965b0e31SSebastian Redl     void bar() noexcept (true) { }
37965b0e31SSebastian Redl   };
38965b0e31SSebastian Redl 
39fa453cfdSSebastian Redl   void (*fptr1)() noexcept;
40fa453cfdSSebastian Redl   void (*fptr2)() noexcept (true);
41965b0e31SSebastian Redl 
42965b0e31SSebastian Redl }
43965b0e31SSebastian Redl 
44fa453cfdSSebastian Redl namespace mix {
45965b0e31SSebastian Redl 
f()46965b0e31SSebastian Redl   void f() throw(int) noexcept { } // expected-error {{cannot have both}}
g()47965b0e31SSebastian Redl   void g() noexcept throw(int) { } // expected-error {{cannot have both}}
48965b0e31SSebastian Redl 
49965b0e31SSebastian Redl }
50fa453cfdSSebastian Redl 
51fa453cfdSSebastian Redl // Sema tests, noexcept specification
52fa453cfdSSebastian Redl 
53fa453cfdSSebastian Redl namespace noex {
54fa453cfdSSebastian Redl 
55fa453cfdSSebastian Redl   struct A {};
56fa453cfdSSebastian Redl 
57*888673b6SJonas Devlieghere   void g1() noexcept(A());     // expected-error {{value of type 'noex::A' is not implicitly convertible to 'bool'}}
583c8e94bcSCorentin Jabot   void g2(bool b) noexcept(b); // expected-error {{noexcept specifier argument is not a constant expression}} expected-note {{function parameter 'b' with unknown value}} expected-note {{here}}
59fa453cfdSSebastian Redl }
60981e37d7SDouglas Gregor 
61981e37d7SDouglas Gregor namespace noexcept_unevaluated {
f(T)624d328b6eSDouglas Gregor   template<typename T> bool f(T) {
63981e37d7SDouglas Gregor     T* x = 1;
64981e37d7SDouglas Gregor   }
65981e37d7SDouglas Gregor 
66981e37d7SDouglas Gregor   template<typename T>
g(T x)67f623c962SRichard Smith   void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { }
68981e37d7SDouglas Gregor 
h()69981e37d7SDouglas Gregor   void h() {
70981e37d7SDouglas Gregor     g(1);
71981e37d7SDouglas Gregor   }
72981e37d7SDouglas Gregor }
734d328b6eSDouglas Gregor 
744d328b6eSDouglas Gregor namespace PR11084 {
754d328b6eSDouglas Gregor template <int X> struct A {
fPR11084::A763c8e94bcSCorentin Jabot   static int f() noexcept(1 / X) { return 10; } // expected-error{{noexcept specifier argument is not a constant expression}} expected-note{{division by zero}}
774d328b6eSDouglas Gregor };
784d328b6eSDouglas Gregor 
f()792e32155bSRichard Smith   template<int X> void f() {
803c8e94bcSCorentin Jabot     int (*p)() noexcept(1 / X); // expected-error{{noexcept specifier argument is not a constant expression}} expected-note{{division by zero}}
812e32155bSRichard Smith   };
822e32155bSRichard Smith 
g()832e32155bSRichard Smith   void g() {
842e32155bSRichard Smith     A<0>::f(); // expected-note{{in instantiation of exception specification for 'f'}}
852e32155bSRichard Smith     f<0>(); // expected-note{{in instantiation of function template specialization}}
862e32155bSRichard Smith   }
874d328b6eSDouglas Gregor }
88883f22efSErich Keane 
89883f22efSErich Keane namespace FuncTmplNoexceptError {
90883f22efSErich Keane   int a = 0;
913c8e94bcSCorentin Jabot   // expected-error@+1{{noexcept specifier argument is not a constant expression}}
f()92883f22efSErich Keane   template <class T> T f() noexcept(a++){ return {};}
g()93883f22efSErich Keane   void g(){
94883f22efSErich Keane     f<int>();
95883f22efSErich Keane   }
96883f22efSErich Keane };
97