public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/89024 - ICE with incomplete enum type
@ 2019-01-24 19:19 Marek Polacek
  2019-01-24 22:17 ` Jason Merrill
  0 siblings, 1 reply; 12+ messages in thread
From: Marek Polacek @ 2019-01-24 19:19 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

This test ICEs since r159006 which added 

   type = ENUM_UNDERLYING_TYPE (type);

to type_promotes_to.  In this test ENUM_UNDERLYING_TYPE is null because we
haven't yet parsed '}' of the enum and the underlying type isn't fixed, and
so checking TYPE_UNSIGNED crashed.

I've added some checks to the test to see if the types seem to be OK; clang++
agrees.

Bootstrapped/regtested on x86_64-linux, ok for trunk/8/7?

2019-01-24  Marek Polacek  <polacek@redhat.com>

	PR c++/89024 - ICE with incomplete enum type.
	* cvt.c (type_promotes_to): Check if prom is non-null.

	* g++.dg/cpp0x/enum37.C: New test.

diff --git gcc/cp/cvt.c gcc/cp/cvt.c
index 82a44f353c7..665e75dd84b 100644
--- gcc/cp/cvt.c
+++ gcc/cp/cvt.c
@@ -1913,7 +1913,8 @@ type_promotes_to (tree type)
       int precision = MAX (TYPE_PRECISION (type),
 			   TYPE_PRECISION (integer_type_node));
       tree totype = c_common_type_for_size (precision, 0);
-      if (TYPE_UNSIGNED (prom)
+      if (prom
+	  && TYPE_UNSIGNED (prom)
 	  && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype))
 	prom = c_common_type_for_size (precision, 1);
       else
diff --git gcc/testsuite/g++.dg/cpp0x/enum37.C gcc/testsuite/g++.dg/cpp0x/enum37.C
new file mode 100644
index 00000000000..eae435c2591
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/enum37.C
@@ -0,0 +1,24 @@
+// PR c++/89024
+// { dg-do run { target c++11 } }
+
+template <class T, class U> struct same;
+template <class T> struct same<T,T> {};
+
+template<class T> T&& declval();
+
+template<typename _To1>
+void __test_aux(_To1);
+
+template<typename _From1, typename _To1,
+        typename = decltype(__test_aux<_To1>(declval<_From1>()))>
+char __test(int);
+
+template<typename, typename>
+int __test(...);
+
+enum E {
+    x = decltype(__test<E, int>(0))(0)
+};
+
+same<E,decltype(x)> s;
+same<unsigned int,__underlying_type(E)> s2;

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

end of thread, other threads:[~2019-01-28 21:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-24 19:19 C++ PATCH for c++/89024 - ICE with incomplete enum type Marek Polacek
2019-01-24 22:17 ` Jason Merrill
2019-01-25 17:00   ` Tim Song
2019-01-25 17:13     ` Marek Polacek
2019-01-25 17:16       ` Jason Merrill
2019-01-26  1:25         ` Marek Polacek
2019-01-27  4:22           ` Jason Merrill
2019-01-28  9:48             ` Christophe Lyon
2019-01-28 16:37               ` Marek Polacek
2019-01-28 17:01                 ` Jason Merrill
2019-01-28 18:11                   ` Marek Polacek
2019-01-28 21:52                     ` 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).