Skip to content
Snippets Groups Projects
Commit 8d8ab5ab authored by Carsten Gräser's avatar Carsten Gräser
Browse files

[!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
parents 80aa79bb f90c50ee
Branches
Tags
1 merge request!665[bugfix] Fix Dune::Hybrid::Impl::Id
Pipeline #18291 passed
......@@ -301,7 +301,7 @@ namespace Impl {
struct Id {
template<class T>
constexpr decltype(auto) operator()(T &&x) const {
constexpr T operator()(T&& x) const {
return std::forward<T>(x);
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment