doc: Document struct-layout-1.exp for ABI checks
[official-gcc.git] / gcc / testsuite / g++.dg / init / array16.C
blob2f6c63dc8dba362c63746188fa23befbe2af905e
1 // Causes timeout for the MMIX simulator on a 3GHz P4 and we can't
2 // have "compile" for some targets and "run" for others.
3 // { dg-do run { target { ! mmix-*-* } } }
5 // Copyright (C) 2004 Free Software Foundation, Inc.
6 // Contributed by Nathan Sidwell 8 Dec 2004 <nathan@codesourcery.com>
8 // PR 16681 too much memory used
9 // Origin:  Matt LaFary <lafary@activmedia.com>
11 // NOTE: This test assumes that 4M instances of struct ELT can fit into
12 //       a 5MB array.
14 struct elt 
16   static int count;
17   static elt*ptr;
18   static int abort;
19   char c;
20   
21   elt ();
22   ~elt ();
23   
26 int elt::count;
27 elt *elt::ptr;
28 int elt::abort;
30 elt::elt ()
31   :c ()
33   if (count >= 0)
34     {
35       if (!ptr)
36         ptr = this;
37       if (count == 100)
38         throw 2;
39       if (this != ptr)
40         abort = 1;
41       count++;
42       ptr++;
43     }
46 elt::~elt ()
48   if (count >= 0)
49     {
50       ptr--;
51       count--;
52       if (ptr != this)
53         abort = 2;
54     }
57 struct foo {
58   elt buffer[4111222];
59   foo() ;
60   bool check () const;
63 foo::foo ()
64   : buffer()
67 bool foo::check () const
69   for (unsigned ix = sizeof (buffer)/ sizeof (buffer[0]); ix--;)
70     if (buffer[ix].c)
71       return false;
72   return true;
75 void *operator new (__SIZE_TYPE__ size, void *p)
77   return p;
80 char heap[5000000];
82 int main ()
84   for (unsigned ix = sizeof (heap); ix--;)
85     heap[ix] = ix;
87   try
88     {
89       foo *f = new (heap) foo ();
90       return 1;
91     }
92   catch (...)
93     {
94       if (elt::count)
95         return 2;
96       if (elt::abort)
97         return elt::abort + 3;
98     }
100   for (unsigned ix = sizeof (heap); ix--;)
101     heap[ix] = ix;
103   elt::count = -1;
104   foo *f = new (heap) foo ();
105   if (!f->check ())
106     return 3;
107   return 0;
110