diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.old-deja/g++.brendan/new2.C | |
download | cbb-gcc-4.6.4-upstream.tar.bz2 cbb-gcc-4.6.4-upstream.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.old-deja/g++.brendan/new2.C')
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.brendan/new2.C | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/new2.C b/gcc/testsuite/g++.old-deja/g++.brendan/new2.C new file mode 100644 index 000000000..2fd55c764 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.brendan/new2.C @@ -0,0 +1,68 @@ +// { dg-do run } +// 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" int printf (const 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 = sizeof (int); + base_ptr = new base; + expected_size = 2 * sizeof (int); + derived_ptr = new derived (); + + if ((new_call_count != 2) || (errors != 0)) + { printf ("FAIL\n"); return 1; } + else + printf ("PASS\n"); + + return 0; +} + +int allocation_space[100]; +int* allocation_ptr = allocation_space; + +void base::operator delete (void* p) +{ +} + +void *base::operator new (size_t size) +{ + int* return_value = allocation_ptr; + + new_call_count++; + if (size != expected_size) + errors++; + allocation_ptr += (size + sizeof(int) - 1) / sizeof(int); + return (void*) return_value; +} |