1 // Test that we've scoped the destructor properly for variables declared 2 // in a conditional. 3 // { dg-do run } 4 5 extern "C" void abort (); 6 7 class C 8 { 9 bool live; 10 public: 11 C(); 12 C(const C &); 13 ~C (); 14 operator bool() const; 15 }; 16 f1()17void f1 () 18 { 19 while (C br = C()) abort (); 20 } 21 f2()22void f2 () 23 { 24 for (; C br = C(); ) abort (); 25 } 26 f3()27void f3 () 28 { 29 if (C br = C()) abort (); 30 } 31 f4()32void f4 () 33 { 34 switch (C br = C()) 35 { 36 default: 37 abort (); 38 case false: 39 break; 40 } 41 } 42 main()43int main() 44 { 45 f1(); f2(); f3(); f4(); 46 return 0; 47 } 48 C()49C::C() 50 { 51 live = true; 52 } 53 C(const C & o)54C::C(const C &o) 55 { 56 if (!o.live) 57 abort (); 58 live = true; 59 } 60 ~C()61C::~C() 62 { 63 live = false; 64 } 65 66 C::operator bool() const 67 { 68 if (!live) 69 abort (); 70 return false; 71 } 72