sys/cdefs.h: add __nodiscard annotation
__nodiscard adds the nodiscard attribute to a function, type or
constructor in C or C++, causing a value so marked to issue a compiler
warning if it is discarded (i.e., not used or assigned) other than by
casting it to void.
this replaces the existing result_use_or_ignore_check, which has a
similar purpose but different semantics. since nodiscard provides
more functionality (at least in GCC) and result_use_or_ignore_check
only had a single user, remove result_use_or_ignore_check.
nodiscard has been supported in C++ since C++17, but only in C since
C23; however, both LLVM and GCC implement it even in older language
versions, so it should always be available with a relatively modern
compiler.
for Clang, nodiscard in C is only available since LLVM 17, but we
can fall back to attribute((warn_unused_result)) which has the
same semantics and provides support back to (at least) LLVM 11.
GCC supports nodiscard in both C and C++ since at least GCC 11.
for GCC, we can't provide a fallback as the semantics of its
warn_unused_result are different, but since __result_use_or_ignore_check
isn't defined for GCC anyway, we don't lose anything here.
MFC after: 2 weeks
Reviewed by: des, emaste
Approved by: des (mentor)
Differential Revision: https://reviews.freebsd.org/D50217