KSVG: fix to include classes used in TQPtrList #41
Merged
MicheleC
merged 1 commits from feat/fix-ksvg-canvas_item-delete
into master
4 months ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'feat/fix-ksvg-canvas_item-delete'
Deleting a branch is permanent. It CANNOT be undone. Continue?
It must be included, or its destructor may not be used in PtrList maitainance.
Hi Obata-san,
I looked at the commit but I am not sure of what the problem is.
TQPtrList is a template list of pointers, so the specified template parameter is only used as a
type *
in the class. Therefore forward declaration of CanvasItem does not seem to be a problem.The m_items list also has the autodelete property set to true, so all the objects own by it will be properly destroyed when m_items is destroyed.
I am actually more surprised that CanvasItemList is only forward declared and the compiler does not complain in the declaration of the
collisions()
methodPossible problem point is in
TQPtrList<type>::deleteItem()
https://mirror.git.trinitydesktop.org/gitea/TDE/tqt3/src/branch/master/src/tools/ntqptrlist.h#L154
delete (type *)d
i.e.delete (CanvasItem *)d
will probably callCanvasItem::~CanvasItem()
and free the memory, with just forward declaration of CanvasItem.But if destructor of
type
is virtual function, destructor should be picked up from its virtual table, or if subclass object oftype
is stored, its destructor will not be called.And if overload operator
delete
oftype
is defined, it must be called istead.For that to be safe,
type
must be fully declared.At least, destructor of CanvasItem is virtual function.
We can merge the PR since it is not a big deal, but I don't think there is a problem in first place. I don't know how the compiler internally instantiate the use of a template, but when it calls the destructor of an object it would call a specific method and the class will have to be well defined at that moment or there would be a compile error. Otherwise it would be possible to write template functions that would call method of non existent classes, isn't it?
In any case, could you review the PR so that we avoid the double inclusion of the same CanvasItem.h file in the .cpp file (I guess it would be included by
#include "KSVGCanvas.moc"
)?Ah, "call
CanvasItem::~CanvasItem()
" is not accurate.its destructor is not found, unknown base class destructor too, and default destructor cannot be created without its member information, then its destructor will not be called even if it really exists.
fb36eda6aa
into master 4 months agoThanks. PR merged and backported.
fb36eda6aa
.