[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: c/9072: -Wconversion should be split into two distinct flags



On Sun, 29 Dec 2002, Zack Weinberg wrote:

> I'm very much in favor of making -Wconversion more useful, but is
> there any reason not to shift the argument-type-conversion warnings
> entirely over to -Wtraditional?  Particularly if the warning is
> avoided for prototypes in system headers (so that 'sinf' and the like
> raise no complaints) -- this would, for instance, catch the occasional
> problem we have with arguments of type 'bool' in GCC itself.
> 
> Then -Wconversion would be entirely for dubious type conversions on
> assignment.

I believe -Wconversion should have exactly the following simple
specification: warn for any implicit conversion that may change a value.  
This implies -Wsign-compare, parts of the existing -Wconversion (but not
those for widening through prototype, etc.), and various cases that there
isn't currently a warning option for (e.g. assigning a signed int to an
unsigned int), and would be useful for security auditing.  The same
intelligence used by -Wsign-compare to avoid warning where problems cannot
in fact arise (e.g. comparing a constant positive signed integer to an
unsigned integer) should be used.  Depending on how many warnings this
generates for reasonable code, there may need to be options to disable
individual parts (beyond the existing -Wno-sign-compare).

Some parts of this might also be useful in -Wtraditional.

Such a -Wconversion implementation would need thorough testcases (probably
a few hundred lines, likely rather longer than the rest of the patch) for
all the different cases of implicit conversion that do warn, or don't warn
because that type conversion can't change values, or don't warn because
that conversion is converting a constant (etc.) to the same value.

-- 
Joseph S. Myers
jsm28@cam.ac.uk



Reply to: