1 // { dg-do run } 2 // Copyright (C) 2002 Free Software Foundation 3 // Contributed by Kriang Lerdsuwanakij <lerdsuwa (at) users.sourceforge.net> 4 5 // Incorrect construction and destruction of multi-dimensional 6 // array of class. 7 8 extern "C" void abort(); 9 extern "C" int printf(const char *, ...); 10 11 int count; 12 int num; 13 14 struct A 15 { 16 A() 17 { 18 if (count == num) 19 throw ""; 20 count++; 21 #ifdef PRINT 22 printf("ctor %p\n", static_cast<void *>(this)); 23 #endif 24 } 25 26 ~A() 27 { 28 count--; 29 #ifdef PRINT 30 printf("dtor %p\n", static_cast<void *>(this)); 31 #endif 32 } 33 }; 34 35 struct Array 36 { 37 A array[2][2][2]; 38 }; 39 40 int main() 41 { 42 for (num = 0; num <= 8; ++num) { 43 count = 0; 44 try { 45 Array A; 46 } 47 catch (...) { 48 } 49 if (count != 0) 50 abort(); 51 } 52 } 53