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  <pola...@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;

Reply via email to