1 #include <libcwd/sys.h>
2 #include <libcwd/debug.h>
3 #include <libcwd/type_info.h>
4 
5 #define builtin_return_address(addr) ((char*)__builtin_return_address(addr) + libcwd::builtin_return_address_offset)
6 
7 template<typename T>
8   class A {
9     int i;
10   public:
A(void)11     A(void) {};
12   };
13 
14 template<typename T>
15   class B {
16     int i;
17   public:
B(void)18     B(void) {};
19     ~B(void);
20   };
21 
22 template<typename T1, typename T2>
23   class C : public A<T1>, public B<T2> {
24     int i;
25   public:
C(void)26     C(void) {};
27   };
28 
29 template<typename T>
~B(void)30 B<T>::~B(void)
31 {
32   Dout(dc::notice, "Calling the destructor of " <<
33                    libcwd::type_info_of(*this).demangled_name() << " (this == " << this << ")");
34   libcwd::alloc_ct const* alloc = libcwd::find_alloc(this);
35   if (sizeof(*this) != alloc->size())
36   {
37     Debug(dc::malloc.off());
38     Debug(libcw_do.push_marker());
39     Debug(libcw_do.marker().assign(": | "));
40     Dout(dc::notice, "This is a base class of an object starting at " << alloc->start());
41     Dout(dc::notice, "The type of the pointer to the allocated object is " <<
42                      alloc->type_info().demangled_name());
43     Debug(libcw_do.marker().assign(": ` "));
44     Dout(dc::notice, "The destructor was called from " << location_ct(builtin_return_address(0)));
45     Debug(dc::malloc.on());
46     Debug(libcw_do.pop_marker());
47   }
48 }
49 
main(void)50 int main(void)
51 {
52   Debug(libcw_do.on());
53   Debug(dc::notice.on());
54   Debug(dc::malloc.on());
55 
56   B<int>* b = new B<int>;				// line 56
57   AllocTag(b, "object `b'");
58   Dout(dc::notice, "b is " << b);
59 
60   C<double, B<char> >* c = new C<double, B<char> >;	// line 60
61   AllocTag(c, "object `c'");
62   Dout(dc::notice, "c is " << c);
63 
64   delete b;
65   delete c;						// line 65
66 
67   return 0;
68 }
69