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

Merge branch 'feature/fix-forloop' into 'master'

[bugfix] Fix possible memory corruption in ForLoop

The reason for perfect forwarding is to also forward r-values as
r-value references such that the called function can do a move
on such values.
As a consequence you should never call `std::forward` on the same
object twice because the second function may get a moved from
object since the first one has already stolen the data. E.g.
for the following operation
```cpp
  template<int i>
  struct Operation
  {
    static void apply(std::vector<int> v)
    {}
  };
```
a call to
```cpp
  Dune::ForLoop<Operation, 0, 1>::apply(std::vector<int>{1,2,3});
```
will pass a moved from vector in an undefined state on the second call.

BTW: The same error existed in the old implementation of `ForLoop`

See merge request !177
parents e683e1df 2277612d
No related branches found
No related tags found
2 merge requests!212Fix link to build system doc,!177[bugfix] Fix possible memory corruption in ForLoop
Pipeline #
......@@ -24,7 +24,7 @@ namespace Dune
static void apply(Args&&... args)
{
Hybrid::forEach(Std::make_index_sequence<last+1-first>{},
[&](auto i){Operation<i+first>::apply(std::forward<Args>(args)...);});
[&](auto i){Operation<i+first>::apply(args...);});
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment