This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wconversion
Patrik Hagglund <patha@softlab.ericsson.se> writes:
> I still think this is confusing. -Wconversion seems to has more than one
> purpose. For example:
> Also, warn if a negative integer constant expression is implicitly
> converted to an unsigned type. For example, warn about the
> assignment `x = -1' if `x' is unsigned. But do not warn about
> explicit casts like `(unsigned) -1'.
> This has nothing to do with prototypes and is intreresting for
> day-to-day use.
> Isn't it better to have two different warnings? One intended for
> day-to-day use and one intended for programs with prototypes rencenlty
> added.
I'd like to second this request. -Wconversion also caught:
ssize_t
function(void)
{
size_t n;
/* ... */
return n;
}
(Admittedly with a somewhat confusing message in gcc 2.95.1 -- yeah, I
know I need to upgrade to 2.95.2.) I found that useful; I think it's
stylistically better to write:
return (ssize_t) n;
which -Wconversion prefers, since it makes it explicit that weird things
may happen for n > maximum positive integer that fits in ssize_t.
--
Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>