-
- Downloads
[!665] [bugfix] Fix Dune::Hybrid::Impl::Id
Merge branch 'bugfix/fix-id' into 'master' ref:core/dune-common 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. See merge request [!665] [!665]: gitlab.dune-project.org/core/dune-common/merge_requests/665
Please register or sign in to comment