[PATCH] Extend -Wint-in-bool-context to suspicious enum values (PR 77700)

Jason Merrill jason@redhat.com
Fri Oct 7 16:54:00 GMT 2016


OK.

On Fri, Oct 7, 2016 at 11:18 AM, Bernd Edlinger
<bernd.edlinger@hotmail.de> wrote:
> Hi!
>
> This extends -Wint-in-bool-context to uses of enum values in boolean
> context, and fixes one place where accidentally an enum value was
> passed to a bool parameter.
>
> I excluded enum values 0 and 1 because that is used in
> gimple-ssa-strength-reduction.c, where we have enums
> which are passed in bool function arguments:
>
> enum stride_status
> {
>    UNKNOWN_STRIDE = 0,
>    KNOWN_STRIDE = 1
> };
>
> enum phi_adjust_status
> {
>    NOT_PHI_ADJUST = 0,
>    PHI_ADJUST = 1
> };
>
> enum count_phis_status
> {
>    DONT_COUNT_PHIS = 0,
>    COUNT_PHIS = 1
> };
>
> I would'nt use an enum in that way, but I think it is
> at least not completely wrong to do it like that...
>
>
> Unfortunately C is less strict with enum values, and from
> and enum we only see an integer value without an enum type
> in C.
>
> Therefore this warning does not work in C, only in C++.
> Also integer constants do not have a source location, so
> the displayed location is usually a bit vague.
> But I think it is still better than no warning at all.
>
>
> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
> Is it OK for trunk?
>
>
> Thanks
> Bernd.



More information about the Gcc-patches mailing list