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> 6 7 // Bug 2823. Inlineing the body of a thunk broke things. But that's 8 // rarely a sensible thing to do anyway. 9 10 #include <cstdio> 11 #include <cstdlib> 12 13 int objCount = 0; 14 15 struct Thing 16 { 17 int count; 18 19 Thing (); 20 Thing (Thing const &src); 21 22 ~Thing (); 23 24 }; 25 Thing()26Thing::Thing () 27 :count (0) 28 { 29 objCount++; 30 std::printf ("%p %s\n", (void *)this,__PRETTY_FUNCTION__); 31 } 32 Thing(Thing const & src)33Thing::Thing (Thing const &src) 34 :count (0) 35 { 36 objCount++; 37 std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__); 38 } 39 ~Thing()40Thing::~Thing () 41 { 42 std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__); 43 if (count) 44 std::abort (); 45 count--; 46 objCount--; 47 } 48 x(Thing name)49void x(Thing name) 50 { 51 // destruct name here 52 } 53 54 class Base 55 { 56 public: 57 virtual void test(const Thing& s) = 0; 58 }; 59 60 class Impl : virtual public Base 61 { 62 public: test(const Thing & s)63 virtual void test(const Thing& s) 64 { 65 x(s); // copy construct temporary 66 } 67 }; 68 main()69int main() 70 { 71 Impl *impl = new Impl(); 72 73 impl->test( Thing ()); // This will use a thunk 74 return objCount != 0; 75 } 76