This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64463

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Reini Urban from comment #0)
> 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.

I don't care if any code is removed or skipped, I want the warning anyway. If
the code isn't removed then it means you're performing unnecessary work,
pessimising your code.

> 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

This wording seems to be aimed at the author of the function, suggesting that
the attribute might be misplaced. I think the warning should instead be aimed
at the caller, telling them to remove the redundant check.

Incorrectly putting the attribute on the function is likely to be much rarer
than unnecessarily checking the result.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]