aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/call.c7
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/enum37.C24
3 files changed, 38 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5ed2b2c578a..2822e7c3a3c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -21,6 +21,13 @@
PR c++/89119 - ICE with value-initialization in template.
* pt.c (tsubst_copy_and_build): Handle RANGE_EXPR.
+ Backport from mainline
+ 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-02-05 Marek Polacek <polacek@redhat.com>
Backported from mainline
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index c3fa4f47c40..f16f2895402 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1396,6 +1396,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. */
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum37.C b/gcc/testsuite/g++.dg/cpp0x/enum37.C
new file mode 100644
index 00000000000..6aa3d4015d7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum37.C
@@ -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;