Skip to content

CWG3071 [dcl.struct.bind] Negative tuple_size in structured binding. #764

@cor3ntin

Description

@cor3ntin

We should specify that a tuple needs to decompose into 0 or more elements. It is unclear what would happen otherwise, ie in this example

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{}; }

This was initially reported as a bug in clang llvm/llvm-project#159563

Proposed change:
In [dcl.struct.bind],

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 non-negative integral constant expression and the structured binding size of E is equal to the value of that expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions