This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/82307] unscoped enum-base incorrect cast
- From: "mukesh.kapoor at oracle dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 05 Oct 2017 17:01:41 +0000
- Subject: [Bug c++/82307] unscoped enum-base incorrect cast
- Auto-submitted: auto-generated
- References: <bug-82307-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82307
Mukesh Kapoor <mukesh.kapoor at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mukesh.kapoor at oracle dot com
--- Comment #4 from Mukesh Kapoor <mukesh.kapoor at oracle dot com> ---
This seems to be a problem in integral promotion in function
type_promotes_to(). The following change fixes the bug:
--- gcc/cp/cvt.c (revision 253270)
+++ gcc/cp/cvt.c (working copy)
@@ -1854,11 +1854,15 @@
tree prom = type;
if (TREE_CODE (prom) == ENUMERAL_TYPE)
prom = ENUM_UNDERLYING_TYPE (prom);
- if (TYPE_UNSIGNED (prom)
- && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype))
- prom = c_common_type_for_size (precision, 1);
- else
- prom = totype;
+ // If enum has fixed underlying type, use that type (bug 82307)
+ if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
+ {
+ if (TYPE_UNSIGNED (prom)
+ && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype))
+ prom = c_common_type_for_size (precision, 1);
+ else
+ prom = totype;
+ }
if (SCOPED_ENUM_P (type))
{
if (abi_version_crosses (6)