[Bug c/81453] New: relational expression involving null pointer not diagnosed with -Wall
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Jul 15 20:07:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81453
Bug ID: 81453
Summary: relational expression involving null pointer not
diagnosed with -Wall
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In C, relational expressions are defined only for pointers to the same object
or array. Using a null pointer in such expressions is undefined. Using a null
pointer constant in a relational expression is a common mistake, yet GCC only
diagnoses such uses with -Wextra or -Wpedantic but not with -Wall. For
example, the following doesn't trigger a warning unless -Wextra is used, even
though the if statement is eliminated because the comparison is false
regardless of the value of i.
The history of the warning suggests that r9580 enabled it under -Wextra in
addition to -pedantic, but the commit comment indicates that -Wall may have
been intended. Unfortunately, no test was added at the time to break the tie.
$ cat a.c && gcc -O2 -S -Wall a.c
int f (int *i)
{
if (i < 0)
return -1;
return 1;
}
More information about the Gcc-bugs
mailing list