Fixes #60143
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
libcxx/include/__numeric/transform_inclusive_scan.h | ||
---|---|---|
45 | I'm not fond of auto here. | |
48 | I'm not sure this approach is valid. If init is provided, T meets the Cpp17MoveConstructible (Table 32) requirements; otherwise, U meets the Cpp17MoveConstructible requirements. If U (decltype(first)) is movable but T (decltype(__init)) isn't this code may violate the precondition. We even require __init to be copyable. I wonder whether that's a bug in the Standard, since I'm unsure how to implement the init version with a non-copyable type. But at least here a copy feels wrong to me. |
libcxx/include/__numeric/transform_inclusive_scan.h | ||
---|---|---|
48 | If T is provided, the spec mandates binary_op(init, unary_op(*first)) are convertible to T, and T meets the Cpp17MoveConstructible. so __init = __b(__init, __u(*__first)); is valid expression (rhs expression convertible to T, and then a move construction) if T is not provided, binary_op(unary_op(*first), unary_op(*first)) is convertible to U, and U meets the Cpp17MoveConstructible. (note U is iterator_traits<Iter>::value_type here. So I think the spec only guarantees that value_type val = ...; decltype(auto) tmp = *first; // not quite, I think if we had range version, we need `iter_common_reference` for this to be valid. val = __b(__u(tmp), __u(*++first)); The legacy algorithm's constraints are not very accurate in general in my opinion. But I think @philnik 's change is an improvement in general. but yes I think we should std::move(__init) here |
I'm not fond of auto here.