2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / optimize2.C
blobb34eae05ebd4417ebbfdd29da00ac17e3fa79641
1 // { dg-do run  }
2 // { dg-options "-O2" }
3 // 
4 // Copyright (C) 2001 Free Software Foundation, Inc.
5 // Contributed by Nathan Sidwell 26 May 2001 <nathan@codesourcery.com>
7 // Bug 2823. Inlineing the body of a thunk broke things. But that's
8 // rarely a sensible thing to do anyway.
10 #include <cstdio>
11 #include <cstdlib>
13 int objCount = 0;
15 struct Thing
17   int count;
19   Thing ();
20   Thing (Thing const &src);
21   
22   ~Thing ();
23   
26 Thing::Thing ()
27   :count (0)
29   objCount++;
30   std::printf ("%p %s\n", (void *)this,__PRETTY_FUNCTION__);
33 Thing::Thing (Thing const &src)
34   :count (0)
36   objCount++;
37   std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__);
40 Thing::~Thing ()
42   std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__);
43   if (count)
44     std::abort ();
45   count--;
46   objCount--;
49 void x(Thing name)
51   // destruct name here
54 class Base
56   public:
57   virtual void test(const Thing& s) = 0;
60 class Impl : virtual public Base
62   public:
63   virtual void test(const Thing& s)
64   {
65     x(s); // copy construct temporary
66   }
69 int main()
71   Impl *impl = new Impl();
72   
73   impl->test( Thing ());        // This will use a thunk
74   return objCount != 0;