We ICE on the following testcase, because std::tuple_element<...,...>::type
is void and for structured bindings we therefore need to create
void & or void && which is invalid. We created such REFERENCE_TYPE and
later ICEd in the middle-end.
The following patch fixes it by diagnosing that.
2021-03-23 Jakub Jelinek <jakub@redhat.com>
PR c++/99650
* decl.c (cp_finish_decomp): Diagnose void initializers when
using tuple_element and get.
* g++.dg/cpp1z/decomp55.C: New test.
: get_tuple_element_type (type, i));
input_location = sloc;
+ if (VOID_TYPE_P (eltype))
+ {
+ error ("%<std::tuple_element<%u, %T>::type%> is %<void%>",
+ i, type);
+ eltype = error_mark_node;
+ }
if (init == error_mark_node || eltype == error_mark_node)
{
inform (dloc, "in initialization of structured binding "
--- /dev/null
+// PR c++/99650
+// { dg-do compile { target c++17 } }
+
+namespace std {
+ template<typename T> struct tuple_size;
+ template<int, typename> struct tuple_element;
+}
+
+struct A {
+ int i;
+ template <int I> void get() { }
+};
+
+template<> struct std::tuple_size<A> { static const int value = 2; };
+template<int I> struct std::tuple_element<I,A> { using type = void; };
+
+A a = { 42 };
+auto [ x, y ] = a; // { dg-error ".std::tuple_element<0, A>::type. is .void." }
+// { dg-message "in initialization of structured binding variable 'x'" "" { target *-*-* } .-1 }