← Back to team overview

dolfin team mailing list archive

Re: [HG DOLFIN] Fix very hard to find bug in dolfin_utils.

 

On Sat, May 16, 2009 at 07:21:11PM +0100, Garth N. Wells wrote:
> 
> Anders Logg wrote:
> > On Sat, May 16, 2009 at 05:08:18PM +0200, DOLFIN wrote:
> > 
> >> One or more new changesets pushed to the primary dolfin repository.
> >> A short summary of the last three changesets is included below.
> >>
> >> changeset:   6163:dff00dceec7cb1e9a8c5b89aa33519d555315ba5
> >> tag:         tip
> >> user:        "Garth N. Wells <gnw20@xxxxxxxxx>"
> >> date:        Sat May 16 16:06:30 2009 +0100
> >> Fix very hard to find bug in dolfin_utils.
> > 
> > --- a/site-packages/dolfin_utils/wrappers/functionspace.py      Fri
> > May 15 15:21:10 2009 +0200
> > +++ b/site-packages/dolfin_utils/wrappers/functionspace.py      Sat
> > May 16 16:06:30 2009 +0100
> > @@ -46,7 +46,7 @@
> >  //  }
> >  // 
> >  
> > -  virtual ~%(classname)s()
> > +  ~%(classname)s()
> >    {
> >    }
> > 
> > Was it just this? 
> 
> Yes.
> 
> I started looking at the bug but couldn't figure out
> > what was wrong. I thought it was always safe to make a destructor
> > virtual.
> >
> 
> I didn't know either that it was a problem. I reduced the problem to
> 
>     const FunctionSpace* V = new CoefficientSpace_f;
>     delete V;
> 
> which failed when the destructor was virtual (there were no other 
> virtual member functions).

The problem was that the destructor of the FunctionSpace base class
was not virtual, but the destructor of the subclass was. The
destructor of the base class needs to be virtual whenever subclasses
are created. GCC will warn when there are other virtual functions but
the destructor is not virtual, but that's just an indication for GCC
that the class is intended as a base class.

  http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.7

Since there are no virtual functions in FunctionSpace, GCC did not
complain about this.

I've verified that it works with virtual in both FunctionSpace and the
wrapper code. The virtual is not needed in the subclass (it will be
virtual anyway).

-- 
Anders

Attachment: signature.asc
Description: Digital signature


References