Thanks for reporting the issue. However, if I compile this:
#include <stdio.h>
int
main (int argc, char **argv)
{
char buf[1000];
return sprintf (buf, "%d", argc);
}
using 'cc -O2 -Wall' on macOS 12.6 21G115 with Apple
clang-1400.0.29.202, I don't get any warning. This is because the return
statement expands to:
return __builtin___sprintf_chk (buf, 0, __builtin_object_size (buf, 2
> 1 ? 1 : 0), "%d", argc);
and there's no deprecation warning for __builtin___sprintf_chk.
With this in mind, perhaps we should dispense with the "# define
_POSIX_C_SOURCE 200809L" business? It is a blunderbuss to deal with a
gnat - admittedly an annoying gnat on some macOS platforms, but perhaps
it's no longer worth worrying about pacifying these older platforms.
Alternatively, perhaps we should do something like the following? That
is, don't bother with pacification if sprintf and vsprintf are macros,
or if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ is not defined (I
stole the latter idea from unistd.in.h).
/* Suppress macOS deprecation warnings for sprintf and vsprintf. */
#if ((defined __APPLE__ && defined __MACH__) \
&& !defined _POSIX_C_SOURCE \
&& !(defined sprintf && defined vsprintf))
# ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
# include <AvailabilityMacros.h>
# endif
# if (defined MAC_OS_X_VERSION_MIN_REQUIRED \
&& 101200 <= MAC_OS_X_VERSION_MIN_REQUIRED)
# define _POSIX_C_SOURCE 200809L
# define _GL_DEFINED__POSIX_C_SOURCE
# endif
#endif