Change policy regarding auto&& in grid range generators?
As stated in the docs of the rangegenerators
We are aware that people like Bjarne Stroustrup and Herb
Sutter advertise the use `auto&&`. Sadly GCC prior to version 6 has a bug (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63506), which
prevents the use of `auto&&` in template functions. For this reason
we currently advice the use of `const auto&`.
Newer compilers emit a warning ("-Wrange-loop-analysis") if the type doesn't match what's deduced by the range. So for example when compiling some code with YaspGrid (range return temporaries/copies) there is a lot of warnings like
warning: loop variable 'element' is always a copy because the range of type ... does not return a reference: use non-reference type.
Turning off this warning is not a good solution IMO since it actually detects wrong usage for example
dune-grid/dune/grid/uggrid/uglbgatherscatter.hh:57:12: note: use reference type 'const Dune::Entity<0, 3, const Dune::UGGrid<3>, UGGridEntity> &' to prevent copying
for (const auto entity : entities(gridView, Codim<codim>()))
^~~~~~~~~~~~~~~~~~~
&
recently fixed in dune-uggrid.
Using auto&&
seems to get rid of the warning and auto&&
collapses to the right type for both situations.
Given that gcc 6 is no longer supported, should this policy be revised?
Edited by Timo Koch