summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/optimize2.C
blob: b34eae05ebd4417ebbfdd29da00ac17e3fa79641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// { dg-do run  }
// { dg-options "-O2" }
// 
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 May 2001 <nathan@codesourcery.com>

// Bug 2823. Inlineing the body of a thunk broke things. But that's
// rarely a sensible thing to do anyway.

#include <cstdio>
#include <cstdlib>

int objCount = 0;

struct Thing
{
  int count;

  Thing ();
  Thing (Thing const &src);
  
  ~Thing ();
  
};

Thing::Thing ()
  :count (0)
{
  objCount++;
  std::printf ("%p %s\n", (void *)this,__PRETTY_FUNCTION__);
}

Thing::Thing (Thing const &src)
  :count (0)
{
  objCount++;
  std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__);
}

Thing::~Thing ()
{
  std::printf ("%p %s\n", (void *)this, __PRETTY_FUNCTION__);
  if (count)
    std::abort ();
  count--;
  objCount--;
}

void x(Thing name)
{
  // destruct name here
}

class Base
{
  public:
  virtual void test(const Thing& s) = 0;
};

class Impl : virtual public Base
{
  public:
  virtual void test(const Thing& s)
  {
    x(s); // copy construct temporary
  }
};

int main()
{
  Impl *impl = new Impl();
  
  impl->test( Thing ());	// This will use a thunk
  return objCount != 0;
}