This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: adding destroyable objects into Ggc
On 18 October 2011 19:03, Basile Starynkevitch wrote:
> On Tue, 18 Oct 2011 18:53:07 +0100
> Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
>> On 18 October 2011 16:12, Basile Starynkevitch wrote:
>> >
>> > Of course, with C++, the destructor routine is really what C++ calls a destructor, e.g
>> > something like extern "C" void my_destructor_for_class_C (class C* p)
>> > { delete (p) p; // call the placement version of operator delete, from <new> C++ library
>> > header. }
>>
>> Why not just call the destructor?
>>
>> ? ?p->~C()
>
> You are right. But I was also thinking of giving a C ABI to these destructors.
Yes, I understand that, I wasn't talking about the C interface.
I assume you haven't tried to compile your suggested code, because
1) your destructor function doesn't match the ggc_destructor_t signature.
2) you can't call placement delete like that
3) the placement delete in <new> is a no-op
You probably want something like this:
extern "C" void my_destructor_for_class_C (void* p)
{ static_cast<C*>(p)->~C(); }