HomeFreeBSD

cdefs.h: Add back fallback define for __printf0like

Description

cdefs.h: Add back fallback define for __printf0like

The format function printf0 is originally a FreeBSD extension. clang has
adopted it as an alias for printf. Starting with gcc 11, gcc doesn't do
a NULL pointer check for fmtarg. Instead, it has to be tagged with a
nonnull attribute, so this gives us the behavior we want.

For earlier gcc and other cmopilers, define it away so do not get false
positives for NULL pointers for the err*/warn* family of functions.
This also fixes -Wsystem-headers by avoiding print0 entirely. My testing
for 67d1a1cd9e77 didn't test that case, so I introduced a regression.

All these compilers need to be considered because __printf0like is used
in err.h and stdlib.h. Since it's used in system headers, it has to
work on all the compilers we support on FreeBSD, not just the ones that
can build FreeBSD itself.

__printf0like will likely be deleted in the future, since the proper way
to do this is with _Nullable or _Nonnull, but the compiler support for
those hasn't been completely evaluated.

Noticed by: jhb
Fixes: 67d1a1cd9e77
Sponsored by: Netflix
Suggestions by: jhb
Differential Revision: https://reviews.freebsd.org/D45836

Details

Provenance
impAuthored on Sat, Jul 6, 4:07 PM
Differential Revision
D45836: cdefs.h: Add back fallback define for __printf0like
Parents
rG9a04df0515c9: cdefs.h: Remove NO_ANSI_KEYWORDS
Branches
Unknown
Tags
Unknown