diff options
author | Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> | 2019-09-04 16:25:21 +0000 |
---|---|---|
committer | Prathamesh Kulkarni <prathamesh3492@gcc.gnu.org> | 2019-09-04 16:25:21 +0000 |
commit | 68e2c1996ec6bde27363ce0db15233ac8cae1c4d (patch) | |
tree | f36d29fb8fb3e378f3c06105410c3d6b2f368994 /gcc/c | |
parent | bc7f7ff954679ac46771f56cbb947a4c19557d98 (diff) | |
download | gcc-68e2c1996ec6bde27363ce0db15233ac8cae1c4d.zip gcc-68e2c1996ec6bde27363ce0db15233ac8cae1c4d.tar.gz gcc-68e2c1996ec6bde27363ce0db15233ac8cae1c4d.tar.bz2 |
Add warning Wenum-conversion for C and ObjC.
The patch enables warning with Wextra due to PR91593 and warnings with
allmodconfig kernel build. Once these issues are resolved, we could
consider promoting it to Wall.
2019-09-04 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
PR c/78736
* doc/invoke.texi: Document -Wenum-conversion.
c-family
* c.opt (Wenum-conversion): New option.
c/
* c-typeck.c (convert_for_assignment): Handle Wenum-conversion.
testsuite/
* gcc.dg/Wenum-conversion.c: New test-case.
From-SVN: r275376
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 15 |
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b7b45f5..285ea18 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2019-09-04 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> + + PR c/78736 + * c-typeck.c (convert_for_assignment): Handle Wenum-conversion. + 2019-08-23 Iain Sandoe <iain@sandoe.co.uk> PR pch/61250 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 2bbf0e2..d4e12eb 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -6726,6 +6726,21 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, } } + if (warn_enum_conversion) + { + tree checktype = origtype != NULL_TREE ? origtype : rhstype; + if (checktype != error_mark_node + && TREE_CODE (checktype) == ENUMERAL_TYPE + && TREE_CODE (type) == ENUMERAL_TYPE + && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type)) + { + gcc_rich_location loc (location); + warning_at (&loc, OPT_Wenum_conversion, + "implicit conversion from %qT to %qT", + checktype, type); + } + } + if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) { warn_for_address_or_pointer_of_packed_member (type, orig_rhs); |