aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-02-13 12:56:16 -0500
committerJason Merrill <jason@gcc.gnu.org>2013-02-13 12:56:16 -0500
commitd0d9cf0ebf69940ed0b95b7b3644553913126286 (patch)
treebd3c684d265fa737fdae061feea6036a68f3cfd2 /gcc
parent78a2ea4199b0292a4fada84baa2db53f6b67e0f0 (diff)
downloadgcc-d0d9cf0ebf69940ed0b95b7b3644553913126286.zip
gcc-d0d9cf0ebf69940ed0b95b7b3644553913126286.tar.gz
gcc-d0d9cf0ebf69940ed0b95b7b3644553913126286.tar.bz2
re PR c++/56155 ([C++11] enumeration with fixed underlying type - enumerators have wrong type within enumerator-list)
PR c++/56155 * decl.c (build_enumerator): Always convert the value to a fixed underlying type. From-SVN: r196022
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c13
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/enum22.C12
3 files changed, 22 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e3b927b..ddd0aa0 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2013-02-13 Jason Merrill <jason@redhat.com>
+ PR c++/56155
+ * decl.c (build_enumerator): Always convert the value to a
+ fixed underlying type.
+
PR c++/56135
* pt.c (tsubst_copy_and_build): Don't forget any new
captures that arose from use of dependent names.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5a9ad2c..eb6c490 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12786,15 +12786,14 @@ incremented enumerator value is too large for %<long%>");
does not fit, the program is ill-formed [C++0x dcl.enum]. */
if (ENUM_UNDERLYING_TYPE (enumtype)
&& value
- && TREE_CODE (value) == INTEGER_CST
- && !int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
+ && TREE_CODE (value) == INTEGER_CST)
{
- error ("enumerator value %E is too large for underlying type %<%T%>",
- value, ENUM_UNDERLYING_TYPE (enumtype));
+ if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
+ error ("enumerator value %E is too large for underlying type %<%T%>",
+ value, ENUM_UNDERLYING_TYPE (enumtype));
- /* Silently convert the value so that we can continue. */
- value = perform_implicit_conversion (ENUM_UNDERLYING_TYPE (enumtype),
- value, tf_none);
+ /* Convert the value to the appropriate type. */
+ value = convert (ENUM_UNDERLYING_TYPE (enumtype), value);
}
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum22.C b/gcc/testsuite/g++.dg/cpp0x/enum22.C
new file mode 100644
index 0000000..e87a31ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum22.C
@@ -0,0 +1,12 @@
+// PR c++/56155
+// { dg-do compile { target c++11 } }
+
+enum e_ : unsigned char { Z_, E_=sizeof(Z_) };
+static_assert( E_ == 1, "E_ should be 1");
+
+template <class T>
+struct A {
+ enum e_ : unsigned char { Z_, E_=sizeof(Z_) };
+};
+
+static_assert ( A<double>::E_ == 1, "E_ should be 1");