summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/noexcept01.C
blob: f314684eae8496088510662fe22d6eb8b8cbc0a4 (plain)
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
82
83
// Test for noexcept-expression
// { dg-options "-std=c++0x -O2" }

#include <typeinfo>

#define SA(X) static_assert(X, #X)

void f();
void g() throw();
SA(noexcept(g()));
SA(!noexcept(f()));
SA(!noexcept(throw 1));
SA(noexcept(42));

struct A
{
  virtual ~A();
};

struct B: public A
{
  virtual ~B();
};

A* ap;

struct C { };
C* cp;

SA (noexcept (dynamic_cast<B*>(ap)));
SA (!noexcept (dynamic_cast<B&>(*ap)));
SA (!noexcept (typeid (*ap)));
SA (noexcept (typeid (*cp)));

SA (!noexcept (true ? 1 : throw 1));
SA (!noexcept (true || true ? 1 : throw 1));

SA (noexcept (C()));

struct D
{
  D() throw();
};

SA (noexcept (D()));

struct E
{
  E() throw();
  ~E();
};

SA (!noexcept (E()));

struct F
{
  virtual void f();
};

SA (noexcept (F()));

struct G
{
  G() = default;
  ~G() = default;
};

SA (noexcept (G()));

template <class T, bool b>
void tf()
{
  SA (noexcept (T()) == b);
}

template void tf<int,true>();
template void tf<E, false>();

// Make sure that noexcept uses the declared exception-specification, not
// any knowledge we might have about whether or not the function really
// throws.
void h() { }
SA(!noexcept(h()));