lclint-interest message 3

Date: Mon, 24 Oct 94 15:08:25 -0400
From: evs (David Evans)
In-Reply-To:'s message of Mon, 24 Oct 94 11:34:16 -0700 <>
Subject: improvement on predicates?

>> From: (Peter Chang)
>> Re the subject line. I'm not entirely happy with using +boolint (or is
>> it -boolint) to stop lint producing warnings on predicates such as:
>> "if (verbose)". Maybe a check for pure assignments in predicates is
>> needed, eg warn against lines like "if (bar = foo())".

> From:
> Peter,
> Dave can check me on this, but I think you can eliminate this problem
> merely by declaring verbose to be a bool, rather than an int, if it is
> intended to be used for logical tests.
> Separately, a check for pure assignments in predicates might be a good
> addition.
> Jim H.

Yes, if verbose is declared as a bool you will not get an error message
here.  If you don't want to declare verbose as a bool here, you can
still supress the error message without making bool and int
indistinguishable in all contexts by using -pred instead.  

However, Peter's suggestion that there should be a way to check for
assignments in predicates is probably a good one.  For the case,

		if (bar = foo())

lclint will report an error if bar is not a bool (unless -pred is used).
But if bar is a bool (and foo returns a bool), lclint with the default
flag settings reports an error (because of bool comparison) for (bar ==
foo()) but not (bar = foo()).

--- Dave
Previous Message Next Message Archive Summary LCLint Home Page David Evans
University of Virginia, Computer Science