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