[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 Eric Gallager changed: What|Removed |Added CC||egallager at gcc dot gnu.org --- Comment #8 from Eric Gallager --- (In reply to Jonathan Wakely from comment #7) > Lots of functions have such requirements and make it the caller's > responsibility to meet those requirements. > > GCC is not a static analyser, you can't expect warnings about every possible > bug in your code. Well, it has a static analyzer *now*...
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 --- Comment #7 from Jonathan Wakely --- Lots of functions have such requirements and make it the caller's responsibility to meet those requirements. GCC is not a static analyser, you can't expect warnings about every possible bug in your code.
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 --- Comment #6 from Jonny Grant --- Jonathan, This is a good point. Where is best to document it? It's very useful to have these warnings, and I was unaware that -Wall would not turn on such a necessary feature, or -O2 Could there be overall documentation on some default warning options that give most useful warnings for safe code development? BTW, I do feel the function could be warned when compiled as an object. void f(int *i) { *i = 1; } There is an implied requirement that the pointer is never null.
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 --- Comment #5 from Jonathan Wakely --- Why add it there and not to every other warning option that depends on interprocedural analysis and inlining? If the dereference and the null pointer are in separate files, then of course the compiler can't warn. That's just how C++ works.
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 --- Comment #4 from Jonny Grant --- Thank you for your replies! Could the -flto tip be added to the -Wnull-dereference documentation? https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Jonathan Wakely --- 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); ^
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 --- Comment #2 from Jonathan Wakely --- That's how C++ works. Each translation unit is compiled separately. It's your job to prevent such errors.
[Bug c++/86177] Wnull-dereference warning for object file compile missing
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86177 --- Comment #1 from Jonny Grant --- If g++ compiles both main.cpp and main2.cpp at the same time (ie no separate obj file stage) it also doesn't give the expected warning. jonny@asus:~/code$ g++-8 -O2 -Wall -Wextra -Wnull-dereference -Wpedantic -o main main2.cpp main.cpp jonny@asus:~/code$