aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cvt.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-05-03 17:16:40 -0400
committerJason Merrill <jason@gcc.gnu.org>2010-05-03 17:16:40 -0400
commitcbb4feb38e39bac728d1a0d053f14d9868d99e8d (patch)
treef66f3527bad37dd8ad2f5c0b5d0966b9ca678f5b /gcc/cp/cvt.c
parente492f63ba96ba25a74ebbfab09cb12d403c0bc1d (diff)
downloadgcc-cbb4feb38e39bac728d1a0d053f14d9868d99e8d.zip
gcc-cbb4feb38e39bac728d1a0d053f14d9868d99e8d.tar.gz
gcc-cbb4feb38e39bac728d1a0d053f14d9868d99e8d.tar.bz2
re PR c++/43680 ([DR 1022] G++ is too aggressive in optimizing away bounds checking with enums)
PR c++/43680 gcc: * c.opt (-fstrict-enums): New. * doc/invoke.texi (C++ Dialect Options): Document -fstrict-enums. gcc/cp: * decl.c (finish_enum): Use the TYPE_MIN_VALUE and TYPE_MAX_VALUE from the selected underlying type unless -fstrict-enums. Set ENUM_UNDERLYING_TYPE to have the restricted range. * cvt.c (type_promotes_to): Use ENUM_UNDERLYING_TYPE. * class.c (check_bitfield_decl): Likewise. From-SVN: r159006
Diffstat (limited to 'gcc/cp/cvt.c')
-rw-r--r--gcc/cp/cvt.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 1f87c5f..5be0b8d 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -682,7 +682,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
the original value is within the range of the enumeration
values. Otherwise, the resulting enumeration value is
unspecified. */
- if (TREE_CODE (expr) == INTEGER_CST && !int_fits_type_p (expr, type))
+ if (TREE_CODE (expr) == INTEGER_CST
+ && !int_fits_type_p (expr, ENUM_UNDERLYING_TYPE (type)))
warning (OPT_Wconversion,
"the result of the conversion is unspecified because "
"%qE is outside the range of type %qT",
@@ -1311,6 +1312,8 @@ type_promotes_to (tree type)
int precision = MAX (TYPE_PRECISION (type),
TYPE_PRECISION (integer_type_node));
tree totype = c_common_type_for_size (precision, 0);
+ if (TREE_CODE (type) == ENUMERAL_TYPE)
+ type = ENUM_UNDERLYING_TYPE (type);
if (TYPE_UNSIGNED (type)
&& ! int_fits_type_p (TYPE_MAX_VALUE (type), totype))
type = c_common_type_for_size (precision, 1);