1 // PR c++/15764 2 // { dg-do run } 3 4 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 5 #define NOEXCEPT_FALSE noexcept (false) 6 #else 7 #define NOEXCEPT_FALSE 8 #endif 9 10 extern "C" void abort (); 11 12 int thrown; 13 14 int as; 15 struct a { aa16 a () { ++as; } ~aa17 ~a () NOEXCEPT_FALSE { --as; if (thrown++ == 0) throw 42; } 18 }; 19 f(a const &)20int f (a const&) { return 1; } f(a const &,a const &)21int f (a const&, a const&) { return 1; } 22 23 int bs; 24 int as_sav; 25 struct b { bb26 b (...) { ++bs; } ~bb27 ~b () { --bs; as_sav = as; } 28 }; 29 30 bool p; g()31void g() 32 { 33 if (p) throw 42; 34 } 35 main()36int main () { 37 thrown = 0; 38 try { 39 b tmp(f (a(), a())); 40 41 g(); 42 } 43 catch (...) {} 44 45 // We throw when the first a is destroyed, which should destroy b before 46 // the other a. 47 if (as_sav != 1) 48 abort (); 49 50 thrown = 0; 51 try { 52 b tmp(f (a())); 53 54 g(); 55 } 56 catch (...) {} 57 58 if (bs != 0) 59 abort (); 60 } 61