On Mon, Nov 21, 2011 at 10:07:51AM +0100, Lars Gullik Bjønnes wrote:
> André Pönitz <andre.poen...@mathematik.tu-chemnitz.de> writes:
> 
> | On Sun, Nov 20, 2011 at 11:46:10PM +0100, Lars Gullik Bjønnes wrote:
> >> 
> >> Even if gcc 4.7 has not been released (quite far from), it might be
> >> nice to test compile with it anyway.
> >
> | Sure.
> |  
> >> Here are the results:
> >>  
> >> GuiWorkArea.cpp: In destructor ‘virtual
> >> lyx::frontend::GuiWorkArea::~GuiWorkArea()’: GuiWorkArea.cpp:327:9:
> >> warning: deleting object of polymorphic class type
> >> ‘lyx::frontend::GuiWorkArea::Private’ which has non-virtual destructor
> >> might cause undefined behaviour [-Wdelete-non-virtual-dtor]
> >
> | I see " : d(new Private)" and "delete d;".  Where is the problem?
> 
> The (potential) problem is a destructor in a parent class that is not
> marked virtual. If anything is allocated in the that class it will not
> be destroyed through the polymorfic pointer.
> 
> It might very well be that gcc is a tad mistaken, but if
> EmbeddedWorkArea, then GuiWorkArea should
> have a virtual destructor.
> 
> (I cannot see how GuiWorkArea::Private plays into this.)

First guess: gcc sees 'virtual' on two member functions but no virtual
destructor, cannot prove that delete operates only on static type ==
dynamic type (even though it could in theory, as all is in one
compilation unit...), and chooses to squeak "just in case" instead of
assuming the programmer roughly knows what he does.

You could try to remove the two 'virtual' in GuiWorkArea::Private 
and check whether the message is gone.

GuiWorkArea itself already inherits a virtual constructor. If that
triggered the compiler warning it would be even more eccentric.

Andre' 

Reply via email to