Skip to content

[bugfix] Fix Dune::Hybrid::Impl::Id

Carsten Gräser requested to merge bugfix/fix-id into master

There's a bug in the current implementation of Dune::Hybrid::Impl::Id. Trying to do 'perfect forwarding' using

  template<class T>
  constexpr decltype(auto) foo()(T&& x) {
    return std::forward<T>(x);
  }

leads to undefined behaviour if you pass an r-value to the function. Then decltype(auto) would be deduced to be an r-value reference such that in

  auto&& bar = foo(expression());

bar would be bound to a temporary which is no longer alive because there's no lifetime prolongation. The correct version is

  template<class T>
  constexpr T foo()(T&& x) {
    return std::forward<T>(x);
  }

When passed an r-value of the raw type E then T is deduced to be E such that we move the temporary into the new value bar. If we pass an l-value of the raw type E, then T is deduced to be either T& or const T& such that we properly return the reference.

Merge request reports

Loading