aboutsummaryrefslogtreecommitdiff
path: root/test/CXX/except/except.spec/p1.cpp
blob: a32f37d55208ecd319b58a027326b96d82ed7fdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s

// Simple parser tests, dynamic specification.

namespace dyn {

  struct X { };

  struct Y { };

  void f() throw() { }

  void g(int) throw(X) { }

  void h() throw(X, Y) { }

  class Class {
    void foo() throw (X, Y) { }
  };

  void (*fptr)() throw();

}

// Simple parser tests, noexcept specification.

namespace noex {

  void f1() noexcept { }
  void f2() noexcept (true) { }
  void f3() noexcept (false) { }
  void f4() noexcept (1 < 2) { }

  class CA1 {
    void foo() noexcept { }
    void bar() noexcept (true) { }
  };

  void (*fptr1)() noexcept;
  void (*fptr2)() noexcept (true);

}

namespace mix {

  void f() throw(int) noexcept { } // expected-error {{cannot have both}}
  void g() noexcept throw(int) { } // expected-error {{cannot have both}}

}

// Sema tests, noexcept specification

namespace noex {

  struct A {};

  void g1() noexcept(A()); // expected-error {{not contextually convertible}}
  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}}

}

namespace noexcept_unevaluated {
  template<typename T> bool f(T) {
    T* x = 1;
  }

  template<typename T>
  void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { }

  void h() {
    g(1);
  }
}

namespace PR11084 {
  template<int X> struct A { 
    static int f() noexcept(1/X) { return 10; }  // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}}
  };

  void g() { A<0>::f(); } // expected-note{{in instantiation of exception specification for 'f' requested here}}
}