Title
Negative tuple_size in structured bindings
Status
open
Section
9.7 [dcl.struct.bind]
Submitter
Corentin Jabot

Created on 2025-09-18.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-09-18.00:00:00

(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. ...
History
Date User Action Args
2025-09-18 00:00:00admincreate