https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463
Bug ID: 64463 Summary: Add warning: returns_nonnull attribute on a function compared against NULL Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: rur...@x-ray.at feature request: Working on gcc.gnu.org/bugzilla/show_bug.cgi?id=64459 I find it difficult to find all occurrences of wrong returns_nonnull attributes. We get those errors, which are fine: error: returns_nonnull attribute on a function not returning a pointer But I'm missing the diagnosis of nonnull return values when they are being wrongly used. Such as: __attribute__((returns_nonnull)) char *myfunc() { ...} if (!myfunc()) { ... /* optimized away */ } I would like to see a warning when a returns_nonnull function is compared against a NULL value, and then actual code is removed or skipped based on that attribute. Which is either a difficult to diagnose declaration error, or a logical error in the usage. warning: returns_nonnull attribute on a function compared against NULL