https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79139

            Bug ID: 79139
           Summary: warning: argument 1 null where non-null expected
                    [-Wnonnull]
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cas43 at cs dot stanford.edu
  Target Milestone: ---

THIS PROGRAM:

void foo(int n)
{
    int * p = 0;
    if(n>0)
    {
        if(4*n/3+2)
            p = new int[n];
    }
    for(int i=0; i<n; i++) p[i] = 0;
    delete [] p;
}

PRODUCES THIS DIAGNOSTIC:

In function ‘void foo(int)’:
cc1plus: warning: argument 1 null where non-null expected [-Wnonnull]
cc1plus: note: in a call to built-in function ‘void* __builtin_memset(void*,
int, long unsigned int)’

WHEN COMPILED LIKE THIS:

g++ prog.cpp -c -O3 -Wall


VERSION:

g++ (GCC) 7.0.0 20161217 (experimental)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

NOTES:

Using -O2 instead does not produce the diagnostic.

Reply via email to