https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108871
Bug ID: 108871 Summary: attribute nonnull does not spot nullptr O2 and above when function inlined Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jg at jguk dot org Target Milestone: --- With Optimizations level 1 it still works. https://godbolt.org/z/6axdfchr8 -fanalyzer -std=c++23 -O3 -Wnonnull -Wall -Wno-analyzer-use-of-uninitialized-value #include <string> std::string make_std_string(const char * const str) __attribute__ ((nonnull)); std::string make_std_string(const char * const str) { return std::string(str); } int main() { const char * a = NULL; std::string result = make_std_string(a); __builtin_puts(result.c_str()); }