http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58272
Bug ID: 58272
Summary: unnecessary vtables emission for pure abstract classes
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: froydnj at gcc dot gnu.org
CC: hubicka at ucw dot cz
Consider the following testcase:
class Interface {
public:
virtual int f() = 0;
};
class Concrete : public Interface {
public:
virtual int f();
};
int
Concrete::f()
{
return 2;
}
Concrete*
do_stuff()
{
Concrete* c = new Concrete();
return c;
}
int
call_f()
{
Interface* i = do_stuff();
return i->f();
}
compiling this on x86-64 with:
g++ -fno-exceptions -S -o - -O2 vtables.cpp -fno-rtti
produces output with a vtable for Interface, which is completely unused in the
compilation unit. (Still does it when omitting -fno-rtti, so it's not a
missing check for typeinfo emission or similar.)
Mozilla has a fair number of these and even though one can eliminate them via
--gc-sections, they still take up time to assemble, write to disk, etc. etc.
Honza and I were talking about them and we did not know whether it was an ABI
requirement that they be emitted or merely a bug in the compiler. G++ appears
to have some smarts about emitting the vtable for Concrete, so I am somewhat
surprised that it doesn't have similar smarts for the vtable for Interface.