Title
Value categories and types for the range in iterable expansion statements
Status
open
Section
8.7 [stmt.expand]
Submitter
Jakub Jelinek

Created on 2025-11-13.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-12-04.23:31:11

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
        constexpr 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
      }
    
    where N is ...
Date: 2025-12-04.23:31:11

(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:58adminsetmessages: + msg8406
2025-11-13 00:00:00admincreate