[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gdb-patches
Subject:    [PATCH] Make dtor of mapped_index_base virtual
From:       simon.marchi () polymtl ! ca (Simon Marchi)
Date:       2017-12-31 13:49:00
Message-ID: 85ac4a723847708e1f2b49f90038a936 () polymtl ! ca
[Download RAW message or body]

On 2017-12-31 05:12, ?????????? ???????????? wrote:
> Hi Simon
> 
> > Do you get a build error or something?
> 
> Yes, I get a build error with Clang:
> 
> dwarf2read.c:25409:5: error: destructor called on non-final 
> 'mapped_index'
> that
> has virtual functions but non-virtual destructor
> [-Werror,-Wdelete-non-virtual-dtor]
> data->index_table->~mapped_index ();
> 
> > Since the goal is that we don't delete through a pointer of this 
> > class, does
> the destructor need to be virtual (not that it would hurt anything)?
> 
> Just to handle the case if someone would delete through a pointer to
> "mapped_index_base" class.
> 
> Thanks,

Hi Pavel,

I think this warning was fixed by the following commit:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=fc898b42e355fef58e6a029799fdd71b9dda5dc6


We don't want anything deleting through a pointer of the base class, 
because (for now) instances of the two child classes (mapped_index and 
mapped_debug_names) are allocated differently.  One is allocated on the 
objfile obstack (some kind of manual memory block allocation) and the 
other is allocated with new.  Trying to delete or manually call the 
destructor through a pointer to mapped_index_base would do the wrong 
thing for one of the two children.  So it's on purpose that 
mapped_index_base's destructor is hidden, and it doesn't matter whether 
or not it is virtual.

Thanks,

Simon


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic