https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110674
Bug ID: 110674
Summary: Structured binding fails with partial specialization
of `std::tuple_element` without `std::size_t` NTTP
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See GCC trunk fail: <https://compiler-explorer.com/z/zevzr89e7>.
See GCC trunk pass: <https://compiler-explorer.com/z/j65vE3os9>.
See GCC 9.5 fail: <https://compiler-explorer.com/z/35fbexaEb>.
See GCC 9.5 pass: <https://compiler-explorer.com/z/5hEPzo7nn>.
```C++
#include <tuple>
#include <type_traits>
struct t { };
struct u {
union { t a; };
template<int I> t& get() { return a; }
};
template<> struct std::tuple_size<u> : std::integral_constant<int, 1> { };
template<int I> struct std::tuple_element<I, u> : std::type_identity<t> { };
int main() {
auto [a] = u{};
}
```
```output
<source>: In function 'int main()':
<source>:11:9: error: invalid use of incomplete type 'struct
std::tuple_element<0, u>'
11 | auto [a] = u{};
| ^
In file included from
/opt/compiler-explorer/gcc-trunk-20230715/include/c++/14.0.0/bits/stl_pair.h:62,
from
/opt/compiler-explorer/gcc-trunk-20230715/include/c++/14.0.0/tuple:38,
from <source>:1:
/opt/compiler-explorer/gcc-trunk-20230715/include/c++/14.0.0/bits/utility.h:80:12:
note: declaration of 'struct std::tuple_element<0, u>'
80 | struct tuple_element;
| ^~~~~~~~~~~~~
<source>:11:9: note: in initialization of structured binding variable 'a'
11 | auto [a] = u{};
| ^
Compiler returned: 1
```