public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/47931] New: missing -Waddress warning for comparison with NULL
@ 2011-02-28 19:43 msebor at gmail dot com
  2011-02-28 19:52 ` [Bug c/47931] " msebor at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gmail dot com @ 2011-02-28 19:43 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: msebor@gmail.com


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-01 10:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 19:43 [Bug c/47931] New: missing -Waddress warning for comparison with NULL msebor at gmail dot com
2011-02-28 19:52 ` [Bug c/47931] " msebor at gmail dot com
2011-03-01  9:05 ` manu at gcc dot gnu.org
2011-03-01 10:16 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).