]> git.ipfire.org Git - thirdparty/gcc.git/blob - libitm/testsuite/libitm.c++/libstdc++-safeexc.C
libstdc++: Make certain exceptions transaction_safe.
[thirdparty/gcc.git] / libitm / testsuite / libitm.c++ / libstdc++-safeexc.C
1 // Tests that the exceptions declared by the TM TS (N4514) as transaction_safe
2 // are indeed that. Thus, this also tests the transactional clones in
3 // libstdc++ and libsupc++.
4
5 // { dg-do run }
6
7 #include <iostream>
8 #include <exception>
9 #include <stdexcept>
10 #include <string>
11
12 using namespace std;
13
14 template<typename T> void thrower(const T& t)
15 {
16 try
17 {
18 atomic_commit
19 {
20 throw t;
21 }
22 }
23 catch (T ex)
24 {
25 if (ex != t) abort ();
26 }
27 }
28
29 template<typename T> void thrower1(const string& what)
30 {
31 try
32 {
33 atomic_commit
34 {
35 throw T ();
36 }
37 }
38 catch (T ex)
39 {
40 if (what != ex.what()) abort ();
41 }
42 }
43
44 template<typename T> void thrower2(const string& what)
45 {
46 try
47 {
48 atomic_commit
49 {
50 throw T (what);
51 }
52 }
53 catch (T ex)
54 {
55 if (what != ex.what()) abort ();
56 }
57 }
58
59
60 int main ()
61 {
62 thrower<unsigned int> (23);
63 thrower<int> (23);
64 thrower<unsigned short> (23);
65 thrower<short> (23);
66 thrower<unsigned char> (23);
67 thrower<char> (23);
68 thrower<unsigned long int> (42);
69 thrower<long int> (42);
70 thrower<unsigned long long int> (42);
71 thrower<long long int> (42);
72 thrower<double> (23.42);
73 thrower<long double> (23.42);
74 thrower<float> (23.42);
75 thrower<void*> (0);
76 thrower<void**> (0);
77 thrower1<exception> ("std::exception");
78 thrower1<bad_exception> ("std::bad_exception");
79 thrower2<logic_error> ("test");
80 thrower2<domain_error> ("test");
81 thrower2<invalid_argument> ("test");
82 thrower2<length_error> ("test");
83 thrower2<out_of_range> ("test");
84 thrower2<runtime_error> ("test");
85 thrower2<range_error> ("test");
86 thrower2<overflow_error> ("test");
87 thrower2<underflow_error> ("test");
88 return 0;
89 }