[Dune] Returning Geometries As Objects

Jö Fahlke jorrit at jorrit.de
Fri Feb 10 23:23:06 CET 2012


Am Fri, 10. Feb 2012, 18:29:24 +0100 schrieb Christian Engwer:
> strange... we didn't experince problem, even with the udg code...

The problem were the entity/intersection wrappers, which did something like

  const Geometry &geometry() {
    return entity.geometry();
  }

This resulted in a (quite correct) compiler warning about returning a
reference to a temporary.  entity.geometry() returns a temporary now, which
has a life-time until the end of the full-expression that is the argument to
the return statement.  That full expression will convert the temporary into a
reference to the temporary, and that reference is then returned from the
wrapper's geometry method.  But by that time the lifetime of the temporary has
already ended.  The reference returned by the wrapper's geometry method thus
points to some free memory on the stack where the temporary geometry object
was previously.  Depending on what you're doing with the returned reference,
and depending on the details of the geometry class, this may or may not work.

By the way, the warnings about this were quite well hidden by the new warnings
about "geometry looks like an object but behaves like a reference".  I'd be
grateful if the grid experts find the time to deal with those soonish.

Have a nice weekend,
Jö.

-- 
Jorrit (Jö) Fahlke, Interdisciplinary Center for Scientific Computing,
Heidelberg University, Im Neuenheimer Feld 368, D-69120 Heidelberg
Tel: +49 6221 54 8890 Fax: +49 6221 54 8884

If God had intended Man to Smoke, He would have set him on Fire.
-- fortune
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20120210/cf6c6779/attachment.sig>


More information about the Dune mailing list