http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47931
Summary: missing -Waddress warning for comparison with NULL
Product: gcc
Version: 4.4.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
The -Waddress option causes gcc to emit a warning for suspicious tests of
addresses of functions and objects. The patch that implemented the feature and
the current test for it indicate that the diagnostic is intended to include the
NULL pointer constant. However, gcc fails to diagnose the pointless comparison
against NULL in the test case below.
http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00972.html
http://gcc.gnu.org/viewcvs/trunk/gcc/testsuite/gcc.dg/Walways-true-1.c
I note that Wstring-literal-comparison-1.c test exercises the ability to
diagnose comparisons of string literals against 0 while at the same time
allowing such comparisons against null pointer constant. Perhaps this feature
conflicts with the ability to issue warnings for constants of other types.
Alternatively, it's possible that the ability to avoid a diagnostic when a null
pointer constant is used is deliberate.
This is a request to either issue the warning in all cases, or to document the
existing behavior so that it can be relied on with some assurance that it will
continue to work this way in future versions of gcc.
$ cat -n t.c && gcc -Waddress -c t.c
1 #define NULL (void*)0
2
3 int i;
4
5 int f() { return &i != 0; }
6 int g() { return &i != NULL; }
t.c: In function āfā:
t.c:5: warning: the address of āiā will never be NULL