summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/array5.C
blob: aeacb31cfaa141c78f63c875ffe8f8ad4b1c84a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// { dg-do run }
// Copyright (C) 2002 Free Software Foundation
// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>

// Incorrect construction and destruction of multi-dimensional
// array of class.

extern "C" void abort();
extern "C" int printf(const char *, ...);

int count;
int num;

struct A
{
	A()
	{
		if (count == num)
			throw "";
		count++;
#ifdef PRINT
		printf("ctor %p\n", static_cast<void *>(this));
#endif
	}

	~A()
	{
		count--;
#ifdef PRINT
		printf("dtor %p\n", static_cast<void *>(this));
#endif
	}
};

struct Array
{
	A array[2][2][2];
};

int main()
{
	for (num = 0; num <= 8; ++num) {
		count = 0;
		try {
			Array A;
		}
		catch (...) {
		}
		if (count != 0)
			abort();
	}
}