This is the mail archive of the
mailing list for the GCC project.
Re: A simple question about virtual destructors.
- From: K <kyb22 at rol dot ru>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 2 Jun 2016 14:48:40 +0300
- Subject: Re: A simple question about virtual destructors.
- Authentication-results: sourceware.org; auth=none
- References: <d4f9a327-ed5b-cc30-5d39-2bf3d2eeaf9d at rol dot ru> <CALvMQwSLBOX1maHR=Ko88tL7H0EX+MZOVLDD7JjcEMXbYEW3iQ at mail dot gmail dot com>
On 06/02/16 13:14, Marcin BaczyÅski wrote:
Yes, this looks like a problem, but then there is a much simple
solution: if base class have a virtual function then it must have a
virtual destructor and if a base class has a virtual destructor then
every class in a hierarchy will have a pointer for destructor in vtbl.
2016-06-02 11:55 GMT+02:00 K <firstname.lastname@example.org>:
My question is what if a compiler will generate a virtual destructor (or
convert a nonvirtual to virtual) in a base class if the base class has at
least one virtual function and classes down in the hierarchy have
nontrivial destructors? In other words make a compiler responsible for
proper destruction of a polymorphic object.
Are there any serious pros against this?
One thing that immediately comes to mind is the compiler would need to
know about those derived classes and their destructors when compiling
the base class.
This suggestion can look stupid
but just think how many type strokes and hours in searching of memory leaks
this could save.
-Wnon-virtual-dtor or -Weffc++ could be of some help there.
Yes, I know -Wall also gave a proper warnings .
I wanted to send this as a suggestion to @isocpp.org mailing list, but
then decided to ask people who work on compiler for their opinions.
This thing with a virtual destructors bothers people for decades and
maybe it is time to make a compiler do proper destruction in this case.