This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 07 Aug 2018 13:13:15 +0000
- Subject: [Bug middle-end/64463] Add warning: returns_nonnull attribute on a function compared against NULL
- Auto-submitted: auto-generated
- References: <bug-64463-4@http.gcc.gnu.org/bugzilla/>
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.