This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/81453] New: relational expression involving null pointer not diagnosed with -Wall
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 15 Jul 2017 20:07:41 +0000
- Subject: [Bug c/81453] New: relational expression involving null pointer not diagnosed with -Wall
- Auto-submitted: auto-generated
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;
}