Created on 2025-11-13.00:00:00 last changed 3 weeks ago
Possible resolution:
Change in 8.7 [stmt.expand] bullet 5.2 as follows:
- ...
- Otherwise, if S is an iterating expansion statement, S is equivalent to:
{ init-statement constexprwhere N is ...auto&&decltype(auto) range = (expansion-initializer) ; constexpr auto begin = begin-expr; // see 8.6.5 [stmt.ranged] constexpr auto end = end-expr; // see 8.6.5 [stmt.ranged] S0 . . . SN-1 }
(From submission #805.)
Consider:
#include <span>
constexpr int arr[3] = { 1, 2, 3 };
consteval std::span<const int> foo() {
return std::span<const int>(arr);
}
int main() {
int r = 0;
template for (constexpr auto m : foo())
r += m;
}
The expansion of this iterable expansion statement contains:
constexpr auto &&range = foo();
The deduction yields std::span<const int>&& for the type of range, and the non-const lifetime-extended temporary causes constant evaluation to fail.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-11-19 21:24:58 | admin | set | messages: + msg8406 |
| 2025-11-13 00:00:00 | admin | create | |