[C++ PATCH] Deprecate -ffriend-injection
[official-gcc.git] / gcc / testsuite / g++.dg / eh / init-temp1.C
blob4996cea230ff5791620b031eaa35847fb005f5cf
1 // PR c++/15764
2 // { dg-do run }
4 #ifdef __GXX_EXPERIMENTAL_CXX0X__
5 #define NOEXCEPT_FALSE noexcept (false)
6 #else
7 #define NOEXCEPT_FALSE
8 #endif
10 extern "C" void abort (); 
12 int thrown; 
14 int as;
15 struct a {
16   a () { ++as; }
17   ~a () NOEXCEPT_FALSE { --as; if (thrown++ == 0) throw 42; }
18 }; 
20 int f (a const&) { return 1; } 
21 int f (a const&, a const&) { return 1; } 
23 int bs;
24 int as_sav;
25 struct b { 
26   b (...) { ++bs; }
27   ~b ()   { --bs; as_sav = as; }
28 }; 
30 bool p;
31 void g()
33   if (p) throw 42;
36 int main () { 
37   thrown = 0;
38   try {
39     b tmp(f (a(), a()));
41     g();
42   }  
43   catch (...) {}
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 ();
50   thrown = 0;
51   try {
52     b tmp(f (a()));
54     g();
55   }  
56   catch (...) {} 
58   if (bs != 0)
59     abort (); 
60