https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84203
Bug ID: 84203 Summary: add -Wsuggest-attribute=returns_nonnull Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The option -Wsuggest-attribute= helps improve code generation by annotating function declarations with attributes like cold, const, pure, malloc and noreturn. However, the option doesn't make it possible to request suggestions for the returns_nonnull attribute. Especially in C++ where functions returning newly allocated memory often never return null (because they throw on failure to allocate), making use of the attribute could further improve generated code. $ cat t.C && gcc -Wall -Wextra -O -S -Wsuggest-attribute=noreturn t.C int f () // -Wsuggest-attribute=noreturn here (good) { throw "not implemented"; } void* f (unsigned n) // missing -Wsuggest-attribute=returns_nonnull { return new char[n]; } t.C: In function ‘int f()’: t.C:1:5: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn] int f () // -Wsuggest-attribute=noreturn here (good) ^