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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If you compile with -flto then the link-time optimizations can see across
translation units and give a warning. Otherwise it's impossible.

Another alternative would be to decorate the function with
__attribute__((nonnull)) which says it requires a non-null pointer:

extern __attribute__((nonnull)) void f(int* i);

Now you'll get a warning when compiling main2.cpp because the compiler can see
you're passing a null pointer to a function that says it requires non-null
pointers:

b.cc: In function ‘int main()’:
b.cc:5:14: warning: null argument where non-null required (argument 1)
[-Wnonnull]
     f(nullptr);
              ^

Reply via email to