On 11/21/18 7:19 AM, Tobias Burnus wrote:
Hello all,

if a class contains any 'virtual ... = 0', it's an abstract class and for an
abstract class, the destructor not added to the vtable.

For a normal
   virtual ~class() { }
that's not a problem as the class::~class() destructor will be generated during
the parsing of the function.

But for
   virtual ~class() = default;
the destructor will be generated via mark_used via the vtable.


If one now declares a derived class and uses it, the class::~class() is 
generated
in that translation unit.  Unless, #pragma interface/implementation is used.

In that case, the 'default' destructor will never be generated.


The following code seems to work both for the big code and for the example;
without '#pragma implementation', the destructor is not generated for the 
example,
only with.

The patch survived boostrapping GCC with default languages on x86-64-gnu-linux
and "make check-g++".*

[One probably could get rid of some of the conditions for generating the code,
e.g. TREE_USED and DECL_DEFAULTED_FN are probably not both needed; one might
want to set some additional DECL to the fn decl.]

You can get at the destructor with CLASSTYPE_DESTRUCTOR rather than walking through TYPE_FIELDS. I'd also check DECL_DEFAULTED_IN_CLASS_P.

I'd also do this in maybe_emit_vtables rather than here, so that it only happens once per class.

Jason

Reply via email to