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

Reply via email to