Skip to content

Non-constant tuple_size in structured binding is accepted #132668

Open
@halbi2

Description

@halbi2
#include <tuple>
struct A {
  template<int> friend int get(A);
};
struct Conv {
  constexpr operator int() { return 2; }
};
template<> struct std::tuple_size<A> {
  static Conv& value; // no definition
};
template<int N> struct std::tuple_element<N, A> {
  using type = int;
};
auto [a,b] = A();

I think this TU is invalid, because tuple_size<A>::value is not an integral constant expression.
clang++ -std=c++20 -c rejects.
clang++ -std=c++23 -c accepts.
Is this intended for P2280? But other compilers support P2280 too, and they all reject this tuple_size code.

I think #132463 could relate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions