Unable to compile Fenics Expression in 2019

I am very new to fenics and hope this is not too naive a question.
I am trying to upgrade from a fenics 2017.2, python2 environment to fenics 2019.0, python3. I am running into problems with the Expression function, which works in the first environment but not the second. Below I try to come up with a minimal working example using the sample cppcode from:
https://fenicsproject.org/docs/dolfin/1.6.0/python/programmers-reference/functions/expression/Expression.html

The following compiles fine in fenics 2017.2, python2

from dolfin import *
code = '''
class MyFunc : public Expression
{
public:

  std::shared_ptr<MeshFunction<std::size_t> > cell_data;

  MyFunc() : Expression()
  {
  }

void eval(Array<double>& values, const Array<double>& x,
          const ufc::cell& c) const
  {
    assert(cell_data);
    const Cell cell(*cell_data->mesh(), c.index);
    switch ((*cell_data)[cell.index()])
    {
    case 0:
      values[0] = exp(-x[0]);
      break;
    case 1:
      values[0] = exp(-x[2]);
      break;
    default:
      values[0] = 0.0;
    }
  }};'''

f = Expression(code, degree=3)

but in 2019.0, python3 I get

Which seems to indicate something’s wrong with the cppcode.

The implementation of Expression changed when one switched from SWIG to PYBIND11.
See this demo for the updated syntax:
https://bitbucket.org/fenics-project/dolfin/src/ec57db53f2b13f1768214829e8b4f80fc32205cf/python/demo/documented/tensor-weighted-poisson/demo_tensor-weighted-poisson.py?at=master#demo_tensor-weighted-poisson.py-115

Ah thank you.

A follow up question: I have tried replacing Expression with UserExpression, and this compiles without error. Is it okay to use this instead of changing the C++ code or will this be problematic?

Shouldn’t be an issue, see for instance:

A final question. In my original project I am doing something like the following:

code = '''
class MyFunc : public Expression
...
      void set_fields(std::shared_ptr<const Function> U)
  {
    _U = U;
  }
}'''

f = UserExpression(code, degree=1)

V = FunctionSpace(mesh, "Lagrange", degree=1) 
U = project(Expression("x[0]*x[0]", degree=1), V)

f.set_fields(U) 

Is the use of “f.set_fields(U)” still appropriate?