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

2025-10-11


3071. Negative tuple_size in structured bindings

Section: 9.7  [dcl.struct.bind]     Status: open     Submitter: Corentin Jabot     Date: 2025-09-18

(From submission #764.)

Consider:

  namespace std {
    template <typename T> struct tuple_size;
  }

  struct S {
    int a;
  };

  template <> struct std::tuple_size<S> {
    static constexpr int value = -1;
  };

  void f(auto) { auto [... a] = S{}; }

There is no protection against negative tuple_size.

Possible resolution:

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

Otherwise, if the qualified-id std::tuple_size<E> names a complete class type with a member named value, the expression std::tuple_size<E>::value shall be a well-formed integral constant expression whose value is non-negative and the structured binding size of E is equal to the that value of that expression. ...