| 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 |
// Not supported on Darwin nor AIX because those lack the support for |
| 6 |
// weak references to undefined functions that we need in libstdc++ to make |
| 7 |
// exceptions transaction-safe. |
| 8 |
// { dg-do run { target { ! { *-*-darwin* powerpc-ibm-aix* } } } } |
| 9 |
|
| 10 |
#include <iostream> |
| 11 |
#include <exception> |
| 12 |
#include <stdexcept> |
| 13 |
#include <string> |
| 14 |
|
| 15 |
using namespace std; |
| 16 |
|
| 17 |
template<typename T> void thrower(const T& t) |
| 18 |
{ |
| 19 |
try |
| 20 |
{ |
| 21 |
atomic_commit |
| 22 |
{ |
| 23 |
throw t; |
| 24 |
} |
| 25 |
} |
| 26 |
catch (T ex) |
| 27 |
{ |
| 28 |
if (ex != t) abort (); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
template<typename T> void thrower1(const string& what) |
| 33 |
{ |
| 34 |
try |
| 35 |
{ |
| 36 |
atomic_commit |
| 37 |
{ |
| 38 |
throw T (); |
| 39 |
} |
| 40 |
} |
| 41 |
catch (T ex) |
| 42 |
{ |
| 43 |
if (what != ex.what()) abort (); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
template<typename T> void thrower2(const string& what) |
| 48 |
{ |
| 49 |
try |
| 50 |
{ |
| 51 |
atomic_commit |
| 52 |
{ |
| 53 |
throw T (what); |
| 54 |
} |
| 55 |
} |
| 56 |
catch (T ex) |
| 57 |
{ |
| 58 |
if (what != ex.what()) abort (); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
int main () |
| 64 |
{ |
| 65 |
thrower<unsigned int> (23); |
| 66 |
thrower<int> (23); |
| 67 |
thrower<unsigned short> (23); |
| 68 |
thrower<short> (23); |
| 69 |
thrower<unsigned char> (23); |
| 70 |
thrower<char> (23); |
| 71 |
thrower<unsigned long int> (42); |
| 72 |
thrower<long int> (42); |
| 73 |
thrower<unsigned long long int> (42); |
| 74 |
thrower<long long int> (42); |
| 75 |
thrower<double> (23.42); |
| 76 |
thrower<long double> (23.42); |
| 77 |
thrower<float> (23.42); |
| 78 |
thrower<void*> (0); |
| 79 |
thrower<void**> (0); |
| 80 |
thrower1<exception> ("std::exception"); |
| 81 |
thrower1<bad_exception> ("std::bad_exception"); |
| 82 |
thrower2<logic_error> ("test"); |
| 83 |
thrower2<domain_error> ("test"); |
| 84 |
thrower2<invalid_argument> ("test"); |
| 85 |
thrower2<length_error> ("test"); |
| 86 |
thrower2<out_of_range> ("test"); |
| 87 |
thrower2<runtime_error> ("test"); |
| 88 |
thrower2<range_error> ("test"); |
| 89 |
thrower2<overflow_error> ("test"); |
| 90 |
thrower2<underflow_error> ("test"); |
| 91 |
return 0; |
| 92 |
} |