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