public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix ICE with structured binding & to incomplete type (PR c++/83217)
@ 2017-11-30 23:17 Jakub Jelinek
  2017-12-15 19:04 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-11-30 23:17 UTC (permalink / raw)
  To: Jason Merrill, Nathan Sidwell; +Cc: gcc-patches

Hi!

When the structured binding decl doesn't have a reference type,
cp_finish_decl makes sure its type is complete, but if it has
a reference type, that doesn't happen and we ICE trying to
access bases of a not yet instantiated type.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

2017-11-30  Jakub Jelinek  <jakub@redhat.com>

	PR c++/83217
	* decl.c (cp_finish_decomp): If decl's type is REFERENCE_TYPE,
	call complete_type (TREE_TYPE (type)).

	* g++.dg/cpp1z/decomp33.C: New test.

--- gcc/cp/decl.c.jj	2017-11-30 11:18:00.000000000 +0100
+++ gcc/cp/decl.c	2017-11-30 15:34:55.873673157 +0100
@@ -7424,7 +7424,9 @@ cp_finish_decomp (tree decl, tree first,
   if (TREE_CODE (type) == REFERENCE_TYPE)
     {
       dexp = convert_from_reference (dexp);
-      type = TREE_TYPE (type);
+      type = complete_type (TREE_TYPE (type));
+      if (type == error_mark_node)
+	goto error_out;
     }
 
   tree eltype = NULL_TREE;
--- gcc/testsuite/g++.dg/cpp1z/decomp33.C.jj	2017-11-30 15:37:58.781405774 +0100
+++ gcc/testsuite/g++.dg/cpp1z/decomp33.C	2017-11-30 15:38:28.006043496 +0100
@@ -0,0 +1,21 @@
+// PR c++/83217
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template <typename T>
+struct S
+{
+  T a;
+};
+
+void
+foo (S<int> *b)
+{
+  auto & [c] = *b;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
+}
+
+void
+bar (S<char> *d)
+{
+  auto [e] = *d;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Fix ICE with structured binding & to incomplete type (PR c++/83217)
  2017-11-30 23:17 [C++ PATCH] Fix ICE with structured binding & to incomplete type (PR c++/83217) Jakub Jelinek
@ 2017-12-15 19:04 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2017-12-15 19:04 UTC (permalink / raw)
  To: Jakub Jelinek, Nathan Sidwell; +Cc: gcc-patches

OK.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-15 19:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-30 23:17 [C++ PATCH] Fix ICE with structured binding & to incomplete type (PR c++/83217) Jakub Jelinek
2017-12-15 19:04 ` Jason Merrill

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).