https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86210
Bug ID: 86210 Summary: [6/7/8/9 Regression] Missing -Wnonnull warning for function defined in the same TU Product: gcc Version: 8.1.1 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- void * declared_not_defined(void * p) __attribute__((nonnull)); inline void * declared_and_defined(void * p) __attribute__((nonnull)); int main() { int * const p = 0; declared_not_defined(p); declared_and_defined(p); } void * declared_and_defined(void * p) { return p; } G++ 5 and 6 fail to give any warnings at all, at any optimisation level. G++ 7 and 8 and trunk only warn at -O1 and higher, and only for one of the two calls: x.cc: In function ‘int main()’: x.cc:8:25: warning: argument 1 null where non-null expected [-Wnonnull] declared_not_defined(p); ~~~~~~~~~~~~~~~~~~~~^~~ x.cc:1:8: note: in a call to function ‘void* declared_not_defined(void*)’ declared here void * declared_not_defined(void * p) __attribute__((nonnull)); ^~~~~~~~~~~~~~~~~~~~ G++ 4.7, 4.8 and 4.9 warns about both calls, without any optimisation: x.cc: In function ‘int main()’: x.cc:8:27: warning: null argument where non-null required (argument 1) [-Wnonnull] declared_not_defined(p); ^ x.cc:9:27: warning: null argument where non-null required (argument 1) [-Wnonnull] declared_and_defined(p); ^ Compiling it as C gives almost the opposite results! I get no warnings for any release before 7.1, and a warning for only one function with 7.1 but only with optimisation, and warnings for both function for 8.1 with optimisation. So for C thigns have been getting gradually better, but worse for C++.