public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix ICE on invalid std::tuple_size<...>::value (PR c++/83205)
@ 2017-11-29 22:35 Jakub Jelinek
  2017-11-30  2:42 ` Martin Sebor
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2017-11-29 22:35 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

If tsize doesn't fit into uhwi, then it obviously can't match the number of
identifiers in the structured binding declaration.  While we could use
compare_tree_int and avoid that way this conversion to uhwi (though,
compare_tree_int does that anyway), for the normal uhwi case we have special
cases in cnt_mismatch shared by the other kinds of structured bindings
that handle smaller and larger cases separately, so I think it is better
to do it this way.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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

	PR c++/83205
	* decl.c (cp_finish_decomp): Handle the case when tsize is not
	error_mark_node, but doesn't fit into uhwi.

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

--- gcc/cp/decl.c.jj	2017-11-28 22:23:34.000000000 +0100
+++ gcc/cp/decl.c	2017-11-29 15:00:24.487658715 +0100
@@ -7518,6 +7518,12 @@ cp_finish_decomp (tree decl, tree first,
 			 "constant expression", type);
 	  goto error_out;
 	}
+      if (!tree_fits_uhwi_p (tsize))
+	{
+	  error_at (loc, "%u names provided while %qT decomposes into "
+			 "%E elements", count, type, tsize);
+	  goto error_out;
+	}
       eltscnt = tree_to_uhwi (tsize);
       if (count != eltscnt)
 	goto cnt_mismatch;
--- gcc/testsuite/g++.dg/cpp1z/decomp32.C.jj	2017-11-29 15:08:59.215378903 +0100
+++ gcc/testsuite/g++.dg/cpp1z/decomp32.C	2017-11-29 15:10:31.576244649 +0100
@@ -0,0 +1,24 @@
+// PR c++/83205
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A { int i; };
+struct B { int i; };
+namespace std {
+  template <typename T> struct tuple_size;
+  template <> struct tuple_size<A> {
+    static constexpr int value = -1;
+  };
+#ifdef __SIZEOF_INT128__
+  template <> struct tuple_size<B> {
+    static constexpr unsigned __int128 value = -1;
+  };
+#endif
+}
+
+auto [a] = A{};	// { dg-error "1 names provided while 'A' decomposes into -1 elements" }
+		// { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
+#ifdef __SIZEOF_INT128__
+auto [b] = B{};	// { dg-error "1 names provided while 'B' decomposes into \[0-9xa-fXA-F]* elements" "" { target int128 } }
+		// { dg-warning "structured bindings only available with" "" { target { c++14_down && int128 } } .-1 }
+#endif

	Jakub

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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 22:35 [C++ PATCH] Fix ICE on invalid std::tuple_size<...>::value (PR c++/83205) Jakub Jelinek
2017-11-30  2:42 ` Martin Sebor
2017-11-30  9:26   ` [C++ PATCH] Plural forms for count != eltscnt structured binding diagnostics Jakub Jelinek
2017-11-30 11:59     ` Nathan Sidwell
2017-11-30 12:09       ` Jakub Jelinek
2017-11-30 13:01         ` Jakub Jelinek
2017-11-30 13:47           ` Jakub Jelinek
2017-11-30 15:51             ` Pedro Alves
2017-12-15 19:01   ` [C++ PATCH] Fix ICE on invalid std::tuple_size<...>::value (PR c++/83205) Jason Merrill
2017-12-15 19:09     ` Jakub Jelinek
2017-12-15 19:46       ` Jakub Jelinek
2017-12-15 21:16         ` 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).