On 3/19/21 4:25 PM, Martin Sebor wrote:
On 3/19/21 12:49 PM, Jakub Jelinek via Gcc-patches wrote:
On Fri, Mar 19, 2021 at 02:17:39PM -0400, Jason Merrill wrote:
--- gcc/cp/decl.c.jj 2021-03-16 21:17:41.014498713 +0100
+++ gcc/cp/decl.c 2021-03-18 19:31:22.430149523 +0100
@@ -8629,6 +8629,11 @@ cp_finish_decomp (tree decl, tree first,
: get_tuple_element_type (type, i));
input_location = sloc;
+ if (VOID_TYPE_P (eltype))
+ {
+ error ("forming reference to void");
If we're going to diagnose it here, we can be clearer that the
problem is
that the tuple element type is void. Or we could SFINAEify
cp_build_reference_type, but that would be a bigger patch.
So, like this?
2021-03-19 Jakub Jelinek <ja...@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.
--- gcc/cp/decl.c.jj 2021-03-19 10:14:18.352935608 +0100
+++ gcc/cp/decl.c 2021-03-19 19:43:11.831960430 +0100
@@ -8629,6 +8629,12 @@ cp_finish_decomp (tree decl, tree first,
: get_tuple_element_type (type, i));
input_location = sloc;
+ if (VOID_TYPE_P (eltype))
+ {
+ error ("%<std::tuple_element<%u,%T>::type%> is void",
void as a type name would ideally be quoted, even though there are
still plenty of unquoted voids in gcc.pot. (There probably also
should be a space after the comma as long as %T formats template
arguments with commas.)
OK with those changes.
Martin
+ i, type);
+ eltype = error_mark_node;
+ }
if (init == error_mark_node || eltype == error_mark_node)
{
inform (dloc, "in initialization of structured binding "
--- gcc/testsuite/g++.dg/cpp1z/decomp55.C.jj 2021-03-19
19:41:03.571357089 +0100
+++ gcc/testsuite/g++.dg/cpp1z/decomp55.C 2021-03-19
19:44:40.600993803 +0100
@@ -0,0 +1,19 @@
+// 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 }
Jakub