OSDN Git Service

/cp
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / noexcept02.C
1 // Test for noexcept-specification
2 // { dg-options "-std=c++0x" }
3
4 #define SA(X) static_assert(X, #X)
5
6 void f();
7 void f() noexcept(false);
8 void f() noexcept(1 == 0);
9 void f();
10
11 SA(!noexcept(f()));
12
13 void g() throw (int);           // { dg-error "previous declaration" }
14 void g() noexcept(false);       // { dg-error "different exception" }
15 void g();
16
17 void h() throw();
18 void h() noexcept;
19 void h() throw();
20 void h() noexcept;
21
22 template <class T>
23 void g (T) noexcept(noexcept(T())); // { dg-error "previous declaration" }
24 template <class T>
25 void g (T) noexcept(noexcept(T(0))); // { dg-error "different exception" }
26
27 template <class T>
28 void f (T) noexcept(noexcept(T()) && noexcept(T()));
29 template <class T>
30 void f (T) noexcept(noexcept(T()) && noexcept(T()));
31 template <class T>
32 void f2(T a) noexcept (noexcept (f (a)));
33
34 struct A { A(); };
35 SA(noexcept(f(1)));
36 SA(!noexcept(f(A())));
37 SA(noexcept(f2(1)));
38 SA(!noexcept(f2(A())));
39
40 template <class... Ts>
41 void f3(Ts... ts) noexcept (noexcept (f(ts...)));
42
43 SA(noexcept(f3(1)));
44 SA(!noexcept(f3(A())));
45
46 template <class T1, class T2>
47 void f (T1, T2) noexcept(noexcept(T1(), T2()));
48
49 struct B { };
50
51 SA(noexcept(f3(1,B())));
52 SA(!noexcept(f3(1,A())));
53 SA(!noexcept(f3(A(),1)));
54 SA(!noexcept(f3(A(),A())));