Open mattgodbolt opened 3 hours ago
I'm a bit out of my depth but maybe something like:
auto value_copy = std::forward<view_ref>(value);
auto it = std::move(value_copy.begin);
// rest of the code uses value_copy
though this forces a copy even in the good case.
The code at:
https://github.com/fmtlib/fmt/blob/720da57baba83b3b1829e20133575e57aa1a8a4f/include/fmt/ranges.h#L661-L666
Does a
and later accesses
value.end
andvalue.sep
.In the case the iterator is not copy constructible then the
view_ref
is an rvalue-reference:which effectively turns the
forward<>
into amove
.clang-tidy
warns on the accesses ofend
andsep
as they are accesses on a moved-from object.I'm not sure that this is really a problem in practice but it seems like something that should be avoided. I can't see an easy way to do so though. I'm not sure we can cast just the iterator easily? Taking a copy of
sep
works but for the same reasons as above we can't copyend
out without a move either.