Using temporaries results in crash

Issue #655 resolved
Franco Milicchio created an issue

As said in the Q&A without any feedback, if I use a temporary the assembly dies with the following exception:

#!

*** -------------------------------------------------------------------------
*** Error:   Unable to evaluate expression.
*** Reason:  Missing eval() function (must be overloaded).
*** Where:   This error was encountered inside Expression.cpp.
*** Process: unknown
*** 
*** DOLFIN version: 1.5.0
*** Git changeset:  f467b66dcfd821ec20e9f9070c7cef5a991dbc42
*** -------------------------------------------------------------------------

A simple code as this is sufficient to see how it can die:

    dolfin::Constant c(3.1415);
    lhs.C0000 = dolfin::Constant(3.1415); // DIE
    lhs.C0000 = c;                        // LIVE

It seems that coefficient assigners in a form use the address of a given constant reference in operator=. As said in the Q&A, this results in errors even with a DirichletBC.

A workaround is to duplicate everything with local variables, but you know better than me that this is error-prone.

I've attached an example, but I might have misunderstood how I need to use Fenics.

Thanks!

Comments (5)

  1. Prof Garth Wells

    This is fixed in the development version, which requires coefficients attached to forms to be shared pointers.

  2. Prof Garth Wells

    You can use containers, as long as the containers hold std::shared_ptrs to the coefficients.

  3. Log in to comment