After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 557290 - Glib::NodeTree doesn't have virtual destructor
Glib::NodeTree doesn't have virtual destructor
Status: RESOLVED INVALID
Product: glibmm
Classification: Bindings
Component: general
2.15.x
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2008-10-21 18:27 UTC by Jonathon Jongsma
Modified: 2009-04-26 22:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jonathon Jongsma 2008-10-21 18:27:50 UTC
Somebody on IRC was having problems subclassing Glib::NodeTree.  He was trying to do something like:

class Foo : public Glib::NodeTree<Glib::Dir>
{...}

Which was failing since Glib::Dir is non-copyable.  So one possible solution would be to change it to be Glib::NodeTree<Glib::Dir*>, but that would require that you free the data member in the destructor, like so:

Foo::~Foo() { delete data(); }

However, Glib::NodeTree does not have a virtual destructor, so this becomes quite risky.  If the node is ever freed as a base class pointer, the data member will not get freed.  

So I guess we should either document very clearly that NodeTree should not be subclassed, or break ABI to make the destructor virtual...
Comment 1 Murray Cumming 2008-10-26 21:16:31 UTC
Classes with no virtual destructors just shouldn't be used polymorphically. If you try to add a virtual method so you can do that then g++ will warn you.

So I don't think people are likely to do this without seeing a warning, and I don't think it needs documentation - we have plenty of other classes with no virtual destructors.

I generally like to have virtual destructors, for flexibility, but other people don't like increasing object sizes unnecessarily.
Comment 2 Jonathon Jongsma 2008-10-27 04:15:37 UTC
fair enough, I just wasn't thinking clearly enough while he was asking the question and I figured that a note might help for others who don't realize that it doesn't have a virtual destructor