1// { dg-do run }
2// Copyright (C) 2002 Free Software Foundation
3// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
4
5// Incorrect construction and destruction of multi-dimensional
6// array of class.
7
8extern "C" void abort();
9extern "C" int printf(const char *, ...);
10
11int count;
12int num;
13
14struct 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
35struct Array
36{
37	A array[2][2][2];
38};
39
40int 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