Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / g++.old-deja / g++.brendan / new2.C
blob2fd55c764e6382747ac089576cac7aa5c86b9ce9
1 // { dg-do run  }
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;
14 struct base {
15         int i;
17         base ()
18         {
19                 i = 7;
20         }
22         void * operator new (size_t size);
23         void operator delete (void*);
26 class derived : public base {
27         int j;
30 int new_call_count = 0;
31 int expected_size = 0;
32 int errors = 0;
34 int main ()
36         base*           base_ptr;
37         derived*        derived_ptr;
39         expected_size = sizeof (int);
40         base_ptr = new base;
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; }
46         else
47           printf ("PASS\n");
49         return 0;
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;
63         new_call_count++;
64         if (size != expected_size)
65                 errors++;
66         allocation_ptr += (size + sizeof(int) - 1) / sizeof(int);
67         return (void*) return_value;