| 1 |
// Testcase from TM TS |
| 2 |
// { dg-options "-std=c++14 -fgnu-tm" } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } } |
| 4 |
|
| 5 |
#include <iostream> |
| 6 |
|
| 7 |
struct B { |
| 8 |
virtual void f() transaction_safe; |
| 9 |
virtual ~B() transaction_safe_dynamic; |
| 10 |
}; |
| 11 |
// pre-existing code |
| 12 |
struct D1 : B |
| 13 |
{ |
| 14 |
void f() override { } // ok |
| 15 |
~D1() override { } // ok |
| 16 |
}; |
| 17 |
struct D2 : B |
| 18 |
{ |
| 19 |
void f() override { std::cout << "D2::f" << std::endl; } // { dg-error "" "transaction-safe f has transaction-unsafe definition" } |
| 20 |
~D2() override { std::cout << "~D2" << std::endl; } // ok |
| 21 |
}; |
| 22 |
int main() |
| 23 |
{ |
| 24 |
D2 * d2 = new D2; |
| 25 |
B * b2 = d2; |
| 26 |
atomic_commit { |
| 27 |
B b; // ok |
| 28 |
D1 d1; // ok |
| 29 |
B& b1 = d1; |
| 30 |
D2 x; |
| 31 |
b1.f(); // ok, calls D1::f() |
| 32 |
delete b2; // undefined behavior: calls unsafe destructor of D2 |
| 33 |
} // { dg-error "" "destructor of D2 is not transaction-safe" } |
| 34 |
} |