PR c++/89024 - ICE with incomplete enum type.
authorMarek Polacek <polacek@redhat.com>
Sun, 27 Jan 2019 19:54:29 +0000 (19:54 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sun, 27 Jan 2019 19:54:29 +0000 (19:54 +0000)
* call.c (standard_conversion): When converting an
ARITHMETIC_TYPE_P to an incomplete type, return NULL.

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

From-SVN: r268320

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/enum37.C [new file with mode: 0644]

index 2d7ab90885ef1ced15305fed654c43de8632a091..c2993db781dca6a852bca5ca29804b3398930c84 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89024 - ICE with incomplete enum type.
+       * call.c (standard_conversion): When converting an
+       ARITHMETIC_TYPE_P to an incomplete type, return NULL.
+       
 2019-01-25  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/88969
index 515a94200324277c842fe1d79afbec5a1493ce01..c74d1b4ebdf604bae4dd0100c7de5db1c15ec8c9 100644 (file)
@@ -1412,6 +1412,13 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
             || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
           || SCOPED_ENUM_P (from))
        return NULL;
+
+      /* If we're parsing an enum with no fixed underlying type, we're
+        dealing with an incomplete type, which renders the conversion
+        ill-formed.  */
+      if (!COMPLETE_TYPE_P (from))
+       return NULL;
+
       conv = build_conv (ck_std, to, conv);
 
       /* Give this a better rank if it's a promotion.  */
index e4d6a1ed4363306e40457a5b917f65154c86ec22..5438d4fd2563abd25d7c0d115e2b0ac235b44b0f 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89024 - ICE with incomplete enum type.
+       * g++.dg/cpp0x/enum37.C: New test.
+
 2019-01-27  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/opt75.adb: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum37.C b/gcc/testsuite/g++.dg/cpp0x/enum37.C
new file mode 100644 (file)
index 0000000..6aa3d40
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/89024
+// { dg-do compile { 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;