2 // GROUPS passed operator-new
3 // Check that if there is a user defined class-specific operator
4 // new for a given class, that operator is invoked when a new
5 // object of the class is requested, regardless of whether or not
6 // there is also a constructor for the given class, and regardless
7 // of whether or not the constructor for the given class is defined
8 // before or after the new operator is even declared.
10 extern "C" int printf (const char *, ...);
12 typedef __SIZE_TYPE__ size_t;
22 void * operator new (size_t size);
23 void operator delete (void*);
26 class derived : public base {
30 int new_call_count = 0;
31 int expected_size = 0;
39 expected_size = sizeof (int);
41 expected_size = 2 * sizeof (int);
42 derived_ptr = new derived ();
44 if ((new_call_count != 2) || (errors != 0))
45 { printf ("FAIL\n"); return 1; }
52 int allocation_space[100];
53 int* allocation_ptr = allocation_space;
55 void base::operator delete (void* p)
59 void *base::operator new (size_t size)
61 int* return_value = allocation_ptr;
64 if (size != expected_size)
66 allocation_ptr += (size + sizeof(int) - 1) / sizeof(int);
67 return (void*) return_value;