1// Test for noexcept-expression
2// { dg-do compile { target c++11 } }
3// { dg-options "-O2" }
4
5#include <typeinfo>
6
7#define SA(X) static_assert(X, #X)
8
9void f();
10void g() throw();
11SA(noexcept(g()));
12SA(!noexcept(f()));
13SA(!noexcept(throw 1));
14SA(noexcept(42));
15
16struct A
17{
18  virtual ~A();
19};
20
21struct B: public A
22{
23  virtual ~B();
24};
25
26A* ap;
27
28struct C { };
29C* cp;
30
31SA (noexcept (dynamic_cast<B*>(ap)));
32SA (!noexcept (dynamic_cast<B&>(*ap)));
33SA (!noexcept (typeid (*ap)));
34SA (noexcept (typeid (*cp)));
35
36SA (!noexcept (true ? 1 : throw 1));
37SA (!noexcept (true || true ? 1 : throw 1));
38
39SA (noexcept (C()));
40
41struct D
42{
43  D() throw();
44};
45
46SA (noexcept (D()));
47
48struct E
49{
50  E() throw();
51  ~E();
52};
53
54SA (noexcept (E()));
55
56struct F
57{
58  virtual void f();
59};
60
61SA (noexcept (F()));
62
63struct G
64{
65  G() = default;
66  ~G() = default;
67};
68
69SA (noexcept (G()));
70
71template <class T, bool b>
72void tf()
73{
74  SA (noexcept (T()) == b);
75}
76
77template void tf<int,true>();
78template void tf<E, true>();
79
80// Make sure that noexcept uses the declared exception-specification, not
81// any knowledge we might have about whether or not the function really
82// throws.
83void h() { }
84SA(!noexcept(h()));
85