public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36299]  New: spurious and undocumented warning with -Waddress for a == 0 when a is an array
@ 2008-05-22  9:05 vincent at vinc17 dot org
  2008-05-22 20:01 ` [Bug c/36299] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: vincent at vinc17 dot org @ 2008-05-22  9:05 UTC (permalink / raw)
  To: gcc-bugs

With -Waddress (implied by -Wall), I get the following warning when I use the
test a == 0 where a is an array: the address of 'a' will never be NULL. This
behavior is undocumented and inconsistent (see below). Here's a testcase:

int main (void)
{
  char a[1], *b;
  b = a;
  if (a == 0)
    return 1;
  else if (a == (void *) 0)
    return 2;
  else if (b == 0)
    return 3;
  else if (b == (void *) 0)
    return 4;
  return 0;
}

gcc warns only for a == 0 (and this is OK to use 0 instead of (void *) 0
because it is a valid form for a null pointer constant).

Moreover this is very similar to code like
  if (1) ...
or code given in bug 12963, for which gcc no longer emits warnings: indeed such
kind of correct and useful code is typically used in macros.


-- 
           Summary: spurious and undocumented warning with -Waddress for a
                    == 0 when a is an array
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vincent at vinc17 dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299


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

end of thread, other threads:[~2014-06-30 19:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-36299-4@http.gcc.gnu.org/bugzilla/>
2011-03-01  9:14 ` [Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array manu at gcc dot gnu.org
2011-03-01 15:05 ` vincent at vinc17 dot org
2011-03-01 15:37 ` manu at gcc dot gnu.org
2011-03-02  1:15 ` vincent at vinc17 dot org
2011-03-02 10:52 ` manu at gcc dot gnu.org
2011-03-02 15:17 ` vincent at vinc17 dot org
2011-03-02 17:06 ` manu at gcc dot gnu.org
2011-03-11 15:15 ` vincent-gcc at vinc17 dot net
2011-04-01 19:36 ` jsm28 at gcc dot gnu.org
2014-06-30 19:38 ` mpolacek at gcc dot gnu.org
2008-05-22  9:05 [Bug c/36299] New: " vincent at vinc17 dot org
2008-05-22 20:01 ` [Bug c/36299] " pinskia at gcc dot gnu dot org
2008-08-23 12:55 ` manu at gcc dot gnu dot org
2008-08-23 20:01 ` vincent at vinc17 dot 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).