aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.brendan/new2.C
blob: 64b3d51e08ae56a2b99e1050404c437f92f95db6 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// GROUPS passed operator-new
// Check that if there is a user defined class-specific operator
// new for a given class, that operator is invoked when a new
// object of the class is requested, regardless of whether or not
// there is also a constructor for the given class, and regardless
// of whether or not the constructor for the given class is defined
// before or after the new operator is even declared.

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

typedef __SIZE_TYPE__ size_t;

struct base {
	int i;

	base ()
	{
		i = 7;
	}

	void * operator new (size_t size);
	void operator delete (void*);
};

class derived : public base {
	int j;
};

int new_call_count = 0;
int expected_size = 0;
int errors = 0;

int main ()
{
	base*		base_ptr;
	derived*	derived_ptr;

	expected_size = 4;
	base_ptr = new base;
	expected_size = 8;
	derived_ptr = new derived ();

	if ((new_call_count != 2) || (errors != 0))
	  printf ("FAIL\n");
	else
	  printf ("PASS\n");

	return 0;
}

char allocation_space[1000];
char* allocation_ptr = allocation_space;

void base::operator delete (void* p)
{
}

void *base::operator new (size_t size)
{
	char* return_value = allocation_ptr;

	new_call_count++;
	if (size != expected_size)
		errors++;
	allocation_ptr = allocation_ptr + size;
	return (void*) return_value;
}