* C++ PATCH for c++/56155 (wrong type for enumerator)
@ 2013-02-13 14:22 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2013-02-13 14:22 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 261 bytes --]
Within the { } of an enum-specifier with a fixed underlying type, the
enumerators are supposed to have that type. A comment in
build_enumerator mentioned that requirement, but nothing actually
implemented it.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 56155.patch --]
[-- Type: text/x-patch, Size: 1949 bytes --]
commit 4944c862e7cd742a4d963bc50ce4ac10707d686b
Author: Jason Merrill <jason@redhat.com>
Date: Tue Feb 12 22:07:34 2013 -0500
PR c++/56155
* decl.c (build_enumerator): Always convert the value to a
fixed underlying type.
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..e87a31c
--- /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");
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-02-13 14:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-13 14:22 C++ PATCH for c++/56155 (wrong type for enumerator) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).