This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[RFC] ordered comparison of pointer with integer zero warning in Wextra
- From: "Manuel LÃpez-IbÃÃez" <lopezibanez at gmail dot com>
- To: gcc <gcc at gcc dot gnu dot org>
- Date: Sun, 17 Dec 2006 12:55:44 +0000
- Subject: [RFC] ordered comparison of pointer with integer zero warning in Wextra
Dear all,
Currently Wextra warns about a pointer compared against integer zero
with <, <=, >, or >=. This warning is not available in C++ (the
documentation does not say this) and it is implemented in
gcc/c-typeck.c (build_binary_op) in this manner:
else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
{
result_type = type0;
if (pedantic || extra_warnings)
pedwarn ("ordered comparison of pointer with integer zero");
}
else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
{
result_type = type1;
if (pedantic)
pedwarn ("ordered comparison of pointer with integer zero");
}
That is, given int *p and -Wextra, the above code warns for p < 0 but
not for 0 > p. Given -pedantic, we warn for both situations. This is
also the only warning activated by both pedantic and -Wextra.
Taking into account the above, is there a reason for this? For me, the
best would be to NOT enable the warning for Wextra, so I don't need to
come up with a name for this warning flag. Otherwise, we would have to
document that the warning is enabled by both pedantic and Wextra, so a
user won't be surprised when the warning does not go away by using the
Wno-* form just because pedantic is enabled.
Please, I would appreciate your comments on this, so I can submit a
patch implementing whichever is thought to be the best approach.
Cheers,
Manuel.