PATCH RFA: Implement -Wenum-compare for C
Ian Lance Taylor
iant@google.com
Wed Apr 1 18:30:00 GMT 2009
Manuel López-Ibáñez <lopezibanez@gmail.com> writes:
> 2009/4/1 Ian Lance Taylor <iant@google.com>:
>>
>> Is that patch OK to commit to mainline?
>>
>
> + /* Warn about comparisons of different enum types. */
> + if (warn_enum_compare
> + && TREE_CODE_CLASS (code) == tcc_comparison
> + && TREE_CODE (type1) == ENUMERAL_TYPE
> + && TREE_CODE (type2) == ENUMERAL_TYPE
> + && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
> + warning (OPT_Wenum_compare,
> + "comparison between %qT and %qT",
> + type1, type2);
> +
>
> IMHO patches adding new warnings should use explicit locations where
> possible (warning_at), particularly if the correct location is
> available. (I am not sure about the latter in this case because the
> patch does not use "diff -p". In any case, even warning_at
> (input_location) should be always better than warning().
Thanks for the comment. The function conviently already has a LOCATION
parameter, so I have changed the code to the following.
Ian
/* Warn about comparisons of different enum types. */
if (warn_enum_compare
&& TREE_CODE_CLASS (code) == tcc_comparison
&& TREE_CODE (type1) == ENUMERAL_TYPE
&& TREE_CODE (type2) == ENUMERAL_TYPE
&& TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
warning_at (location, OPT_Wenum_compare,
"comparison between %qT and %qT",
type1, type2);
More information about the Gcc-patches
mailing list