This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2026-03-27


3135. constexpr structured bindings with prvalues from tuples

Section: 9.7  [dcl.struct.bind]     Status: ready     Submitter: Barry Revzin     Date: 2025-11-14

(From submission #807.)

In the tuple case, e.get<i>() or get<i>(e) is used, but the case that those function calls return a prvalue is not properly handled for constexpr. For example, P1789R3 (Library Support for Expansion Statements) added constexpr T get(integer_sequence<...>).

Specific example:

  constexpr auto [...Is] = std::make_index_sequence<2>();

decomposes into:

  constexpr auto e = std::integer_sequence<size_t, 0, 1>();
  constexpr size_t&& Is#0 = 0;   // temporary is mutable
  constexpr size_t&& Is#1 = 1;

Structured bindings for prvalues should use a non-reference type.

Proposed resolution (approved by CWG 2026-03-27):

Change in 9.7 [dcl.struct.bind] paragraph 7 as follows:

... Given the type Ti designated by std::tuple_element<i, E>::type and the type Ui designated by either Ti & or Ti && where Ui is an lvalue reference if the initializer is an lvalue and an rvalue reference otherwise, defined as Ti if the initializer is a prvalue, as "lvalue reference to Ti" if the initializer is an lvalue, or as "rvalue reference to Ti" otherwise, variables are introduced with unique names ri as follows:
  S Ui ri = initializer ;