1// { dg-do compile } 2// { dg-options "-fgnu-tm -O1" } 3 4__attribute__((transaction_safe)) 5void* operator new (__SIZE_TYPE__); 6 7__attribute__((transaction_pure)) 8inline int atomic_exchange_and_add( int * pw, int dv ) 9{ 10 int r; 11 __asm__ ("" : "=r"(r)); 12 return r; 13} 14 15class sp_counted_base 16{ 17protected: 18 int use_count_; // #shared 19public: 20 __attribute__((transaction_safe)) 21 virtual void dispose() = 0; // nothrow 22 23 __attribute__((transaction_safe)) 24 void release() // nothrow 25 { 26 if( atomic_exchange_and_add( &use_count_, -1 ) == 1 ) 27 { 28 dispose(); 29 } 30 } 31}; 32 33class sp_counted_base_x86 : public sp_counted_base 34{ 35public: 36 void dispose() 37 { 38 release(); 39 } 40}; 41 42class shared_count 43{ 44private: 45 sp_counted_base * pi_; 46public: 47 int j; 48 __attribute__((transaction_safe)) 49 shared_count(): pi_(new sp_counted_base_x86()), j(0) 50 { 51 } 52 __attribute__((transaction_safe)) 53 ~shared_count() // nothrow 54 { 55 if( pi_ != 0 ) pi_->release(); 56 } 57}; 58 59volatile int i = 1; 60shared_count * c; 61int main() 62{ 63 if ( i == 0) { 64 __transaction_atomic { 65 shared_count sc; 66 } 67 } 68 return 0; 69} 70