Rebase.
[official-gcc.git] / gcc / testsuite / g++.dg / eh / scope1.C
blob8d553d8295b26bcbc081402ccac46106423bbac5
1 // Test that we've scoped the destructor properly for variables declared
2 // in a conditional.
3 // { dg-do run }
5 extern "C" void abort ();
7 class C
9   bool live;
10  public:
11   C();
12   C(const C &);
13   ~C ();
14   operator bool() const;
17 void f1 ()
19   while (C br = C()) abort ();
22 void f2 ()
24   for (; C br = C(); ) abort ();
27 void f3 ()
29   if (C br = C()) abort ();
32 void f4 ()
34   switch (C br = C()) /* { dg-warning "switch condition has" } */
35     {
36     default:
37       abort ();
38     case false:
39       break;
40     }
43 int main()
45   f1(); f2(); f3(); f4();
46   return 0;
49 C::C()
51   live = true;
54 C::C(const C &o)
56   if (!o.live)
57     abort ();
58   live = true;
61 C::~C()
63   live = false;
66 C::operator bool() const
68   if (!live)
69     abort ();
70   return false;