diff options
author | no-author <no-author@gcc.gnu.org> | 2004-12-09 13:59:26 +0000 |
---|---|---|
committer | no-author <no-author@gcc.gnu.org> | 2004-12-09 13:59:26 +0000 |
commit | 63f5e6a7d36ecb7c5e3afcbb3ec92154a6290d88 (patch) | |
tree | 689a368afe0732af4f5d7aeadaac10ba3ee9f939 | |
parent | f650a7669ffc003536e3e4f1bdbf8ee2632cdc12 (diff) |
This commit was manufactured by cvs2svn to create branch
'gcc-3_4-rhl-branch'.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-3_4-rhl-branch@91949 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/testsuite/g++.dg/init/array15.C | 46 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/array16.C | 106 |
2 files changed, 152 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/init/array15.C b/gcc/testsuite/g++.dg/init/array15.C new file mode 100644 index 00000000000..17160d07611 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array15.C @@ -0,0 +1,46 @@ +// { dg-do run } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 8 Dec 2004 <nathan@codesourcery.com> + +// PR 16681 too much memory used +// Origin: Matt LaFary <lafary@activmedia.com> + +struct foo { + unsigned char buffer[4111222]; + foo() ; + bool check () const; +}; + +foo::foo () + : buffer() +{} + +bool foo::check () const +{ + for (unsigned ix = sizeof (buffer); ix--;) + if (buffer[ix]) + return false; + return true; +} + +void *operator new (__SIZE_TYPE__ size, void *p) +{ + return p; +} + +char heap[5000000]; + +int main () +{ + for (unsigned ix = sizeof (heap); ix--;) + heap[ix] = ix; + + foo *f = new (heap) foo (); + + if (!f->check ()) + return 1; + return 0; +} + + diff --git a/gcc/testsuite/g++.dg/init/array16.C b/gcc/testsuite/g++.dg/init/array16.C new file mode 100644 index 00000000000..fa4c1b65088 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array16.C @@ -0,0 +1,106 @@ +// { dg-do run } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 8 Dec 2004 <nathan@codesourcery.com> + +// PR 16681 too much memory used +// Origin: Matt LaFary <lafary@activmedia.com> + + +struct elt +{ + static int count; + static elt*ptr; + static int abort; + char c; + + elt (); + ~elt (); + +}; + +int elt::count; +elt *elt::ptr; +int elt::abort; + +elt::elt () + :c () +{ + if (count >= 0) + { + if (!ptr) + ptr = this; + if (count == 100) + throw 2; + if (this != ptr) + abort = 1; + count++; + ptr++; + } +} + +elt::~elt () +{ + if (count >= 0) + { + ptr--; + count--; + if (ptr != this) + abort = 2; + } +} + +struct foo { + elt buffer[4111222]; + foo() ; + bool check () const; +}; + +foo::foo () + : buffer() +{} + +bool foo::check () const +{ + for (unsigned ix = sizeof (buffer)/ sizeof (buffer[0]); ix--;) + if (buffer[ix].c) + return false; + return true; +} + +void *operator new (__SIZE_TYPE__ size, void *p) +{ + return p; +} + +char heap[5000000]; + +int main () +{ + for (unsigned ix = sizeof (heap); ix--;) + heap[ix] = ix; + + try + { + foo *f = new (heap) foo (); + return 1; + } + catch (...) + { + if (elt::count) + return 2; + if (elt::abort) + return elt::abort + 3; + } + + for (unsigned ix = sizeof (heap); ix--;) + heap[ix] = ix; + + elt::count = -1; + foo *f = new (heap) foo (); + if (!f->check ()) + return 3; + return 0; +} + + |