This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Devirtualize virtual call hierarchy if just base dtor exists
- From: Martin LiÅka <mliska at suse dot cz>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 22 Oct 2014 18:08:35 +0200
- Subject: Re: Devirtualize virtual call hierarchy if just base dtor exists
- Authentication-results: sourceware.org; auth=none
- References: <5447CA0D dot 7070704 at suse dot cz> <20141022153024 dot GC343 at x4>
On 10/22/2014 05:30 PM, Markus Trippelsdorf wrote:
On 2014.10.22 at 17:15 +0200, Martin LiÅka wrote:
Hello.
I've been playing with following example:
#include <stdlib.h>
class Base
{
public:
virtual ~Base() {}
};
class Derived: public Base
{
};
#define N 1000
int main()
{
Base **b = (Base **)malloc (sizeof(Base *) * N);
for (unsigned i = 0; i < N; i++)
b[i] = new Derived();
for (unsigned i = 0; i < N; i++)
delete b[i];
return 0;
}
Where I would like to somehow give an advice to devirtualize
machinery. My motivation is to inline destruction in 'delete b[i]'.
'final' keyword does not solve my problem:
a.c:9:7: error: virtual function âvirtual Derived::~Derived()â
class Derived: public Base
^
a.c:6:11: error: overriding final function âvirtual Base::~Base()â
virtual ~Base() final {}
What about:
class Derived final: public Base {};
Yes, that works, but it allows one to have a different class that inherits from the Base class.
Martin