Created on 2025-12-04.00:00:00 last changed 7 days ago
Possible resolution:
Change in 6.8.7 [class.temporary] paragraph 9 (as modified by issue 3043) as follows:
The sixth context is when a temporary object is created in the expansion-initializer of an iterating oradestructuring expansion statement. If such a temporary object would otherwise be destroyed at the end of that expansion-initializer, the object persists for the lifetime of the reference initialized by the expansion-initializer, if any.
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 constexpropt auto&& range = expansion-initializer ; constexpropt auto begin = begin-expr; // see 8.6.5 [stmt.ranged]where N is the result of evaluating the expressionconstexpr auto end = end-expr; // see 8.6.5 [stmt.ranged]S0 . . . SN-1 }[&] consteval { std::ptrdiff_t result = 0;and Si isfor (auto i = begin ; i != end ; ++i, ++result);auto b = begin-expr ; auto e = end-expr ; for (; b != e; ++b) ++result; return result; // distance from begin to end }(){ constexpropt auto iter = begin + i; for-range-declaration = *iter ; compound-statement }The variables range, begin,end,and iter are defined for exposition only. The keyword constexpr is present in the declaration of range and begin if and only if constexpr is one of the decl-specifiers of the decl-specifier-seq of the for-range-declaration.[Note 1: The instantiation is ill-formed if range is not a constant expression (7.7 [expr.const]). —end note]- ...
(From submission #805.)
(Split off from issue 3131.)
In order to allow expansion over non-constant std::array (which does have a compile-time size), the constexpr in the range declaration in 8.7 [stmt.expand] bullet 5.2 should be optional, similar to the destructuring case.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-12-04 23:31:25 | admin | set | messages: + msg8430 |
| 2025-12-04 00:00:00 | admin | create | |