public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9436] c++: Diagnose references to void in structured bindings [PR99650] Date: Tue, 20 Apr 2021 23:33:50 +0000 (GMT) [thread overview] Message-ID: <20210420233350.4F9A53AA7C99@sourceware.org> (raw) https://gcc.gnu.org/g:dd320787b4eb11521e3ae3f9aa9504b31ee08c36 commit r9-9436-gdd320787b4eb11521e3ae3f9aa9504b31ee08c36 Author: Jakub Jelinek <jakub@redhat.com> Date: Tue Mar 23 10:23:42 2021 +0100 c++: Diagnose references to void in structured bindings [PR99650] 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. (cherry picked from commit d5e379e3fe19362442b5d0ac608fb8ddf67fecd3) Diff: --- gcc/cp/decl.c | 6 ++++++ gcc/testsuite/g++.dg/cpp1z/decomp55.C | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 1b20d13e4b3..782f0f6e60f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7842,6 +7842,12 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) : 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 " diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp55.C b/gcc/testsuite/g++.dg/cpp1z/decomp55.C new file mode 100644 index 00000000000..bb4bf754abb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp55.C @@ -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 }
reply other threads:[~2021-04-20 23:33 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210420233350.4F9A53AA7C99@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).