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