[cfe-commits] [Patch] Checker for assignment of non-Boolean value to Boolean variable

David Blaikie dblaikie at gmail.com
Thu Dec 8 15:47:20 PST 2011


On Thu, Dec 8, 2011 at 3:35 PM, Ryan Govostes <rzg at apple.com> wrote:
>
> On Dec 8, 2011, at 3:19 PM, David Blaikie wrote:
>
> I haven't looked through the code, but I sort of assumed since this
> was an SA warning that it would be trying to find a particular more
> bug-like code, such as looking for int->bool where the int was certain
> to be neither zero nor one, say.
>
>
> Yes, this is what it does.
>
> The checker helps avoid situations in which your program ends up in an
> unexpected state due to both (x == YES) and (x == NO) being false.

Hmm - that doesn't sound like what I gathered from the description.
Are we talking about a Boolean type that has two well defined states &
lots of other ill defined states (like Win32 BOOL - which is just a
macro around an unsigned int along with two macros (TRUE and FALSE))?

Yeah, in that case it makes sense to have a check that ensures that
pseudo-bool only ever contains the two well defined states. This
totally makes sense as an SA diagnostic, etc.

If, on the other hand, 'x' is an int and someone's comparing it to
true or false - I'd say that's probably a reasonable compiler warning.
Or if we're complaining about int assigned to C++ 'bool' just because
it collapses all non-zero values to 'true', then I don't really get
it.

Sorry for my confusion,
- David



More information about the cfe-commits mailing list