This is a pretty obvious patch. We were permitting a scoped enum initializer of an another enum to silently decay to int. That's not right, only unscoped enums have that privilege.

committed.

nathan
2015-05-24  Nathan Sidwell  <nat...@acm.org>

	cp/
	PR c++/66243
	* decl.c (build_enumerator): Don't silently convert scoped enums.

	testsuite/
	PR c++/66243
	* g++.dg/cpp0x/pr66243.C: New.

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 223613)
+++ cp/decl.c	(working copy)
@@ -13097,7 +13097,8 @@ build_enumerator (tree name, tree value,
 	      if (tmp_value)
 		value = tmp_value;
 	    }
-	  else if (! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
+	  else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
+		   (TREE_TYPE (value)))
 	    value = perform_implicit_conversion_flags
 	      (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
 	       LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
Index: testsuite/g++.dg/cpp0x/pr66243.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr66243.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/pr66243.C	(working copy)
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+
+enum class A
+{
+  X
+};
+
+enum class B
+{
+  X = A::X // { dg-error "could not convert" }
+};
+

Reply via email to