* localtime.c (tzloadbody): Move recently-added static_assert to the top level. This pacifies some pre-C23 compilers, so that they do not warn about nested extern declarations. * private.h (static_assert): Comment about this. Also, do not define if already defined; this can happen if a wrapper source file includes <assert.h> before us in C11. --- localtime.c | 4 +++- private.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/localtime.c b/localtime.c index 24972b20..a78962a6 100644 --- a/localtime.c +++ b/localtime.c @@ -756,6 +756,9 @@ ATTRIBUTE_NONSTRING #endif static char const tzdirslash[sizeof TZDIR + OPENAT_TZDIR] = TZDIR "/"; enum { tzdirslashlen = sizeof TZDIR }; +#ifdef PATH_MAX +static_assert(tzdirslashlen <= PATH_MAX); /* Sanity check; assumed below. */ +#endif /* Local storage needed for 'tzloadbody'. */ union local_storage { @@ -866,7 +869,6 @@ tzloadbody(char const *name, struct state *sp, char tzloadflags, char *cp; size_t fullnamesize; #ifdef PATH_MAX - static_assert(tzdirslashlen <= PATH_MAX); size_t namesizemax = PATH_MAX - tzdirslashlen; size_t namelen = strnlen (name, namesizemax); if (namesizemax <= namelen) diff --git a/private.h b/private.h index befa6db1..2008660d 100644 --- a/private.h +++ b/private.h @@ -82,8 +82,9 @@ # include <stdbool.h> #endif -#if __STDC_VERSION__ < 202311 -# undef static_assert +/* For pre-C23 compilers, a substitute for static_assert. + Some of these compilers may warn if it is not used at the top level. */ +#if __STDC_VERSION__ < 202311 && !defined static_assert # define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1] #endif -- 2.48.1