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

--- Comment #7 from Ivan Sorokin <vanyacpp at gmail dot com> ---
For me the support for operator new works well for trivially constructible
types. For a non-trivially constructible type I got a false positive:

struct foo { foo(); };

int main()
{
    delete new foo();
}

In function 'int main()':
cc1plus: warning: use of possibly-NULL 'operator new(1)' where non-null
expected [CWE-690] [-Wanalyzer-possible-null-argument]
  'int main()': event 1
    |
    |<source>:5:20:
    |    5 |     delete new foo();
    |      |                    ^
    |      |                    |
    |      |                    (1) this call could return NULL
    |
  'int main()': event 2
    |
    |cc1plus:
    | (2): argument 'this' ('operator new(1)') from (1) could be NULL where
non-null expected
    |
<source>:1:14: note: argument 'this' of 'foo::foo()' must be non-null
    1 | struct foo { foo(); };
      |              ^~~
Compiler returned: 0

https://godbolt.org/z/nPff9EGsY

Also the error location seems to be wrong. Removing "()" from "delete new
foo()" fixes the error location.

Reply via email to