Skip to content

Cherry-pick: Merge branch 'feature/fix-forloop' into 'master'

Carsten Gräser requested to merge cherry-pick-b8d06d5c into releases/2.5

[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

  template<int i>
  struct Operation
  {
    static void apply(std::vector<int> v)
    {}
  };

a call to

  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 (merged)

Merge request reports