[clang] [clang] Implement CWG3135 - constexpr structured bindings with prvalues from tuples (PR #191880)

Matthias Wippich via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 06:10:38 PDT 2026


Tsche wrote:

Am I missing any changes here? Given a small test against integer_sequence:
```cpp
// integer_sequence
using size_t = decltype(sizeof(0));
namespace std {
template <class Tp> struct tuple_size;
template <class Tp> struct tuple_size<Tp const> : tuple_size<Tp> {};
template <size_t I, class Tp> struct tuple_element;
} // namespace std

template <class _Tp, _Tp... _Indices> struct integer_sequence {};
template <class _Tp, _Tp... _Indices>
struct std::tuple_size<integer_sequence<_Tp, _Indices...>> {
  static constexpr size_t value = sizeof...(_Indices);
};
template <size_t _Ip, class _Tp, _Tp... _Indices>
struct std::tuple_element<_Ip, integer_sequence<_Tp, _Indices...>> {
  using type = _Tp;
};
template <size_t _Ip, class _Tp, _Tp... _Indices>
struct std::tuple_element<_Ip, const integer_sequence<_Tp, _Indices...>> {
  using type = _Tp;
};
template <size_t _Ip, class _Tp, _Tp... _Indices>
[[nodiscard]] constexpr _Tp get(integer_sequence<_Tp, _Indices...>) noexcept {
  return _Indices...[_Ip];
}

// test
template <int> void f() {}

template <typename = void> void foo() {
  static constexpr auto [Is] = integer_sequence<int, 42>{};
  static_assert(__is_same_as(decltype(Is), int));
  f<Is>();
}

int main() { foo<void>(); }
```

This still fails with
```
test.cpp:40:3: error: no matching function for call to 'f'
   40 |   f<Is>();
      |   ^~~~~
test.cpp:31:21: note: candidate template ignored: invalid explicitly-specified argument for 1st template
      parameter
   31 | template <int> void f() {}
      |                     ^
1 error generated.
```

with and without this patch. Interestingly clang 22 accepts it with the following change applied:
```cpp
template <size_t _Ip, class _Tp, _Tp... _Indices>
struct std::tuple_element<_Ip, const integer_sequence<_Tp, _Indices...>> {
  using type = const _Tp;
};
```

I was under the impression that CWG3135 addresses this without having to change library? 

https://github.com/llvm/llvm-project/pull/191880


More information about the cfe-commits mailing list