From 5076e9b5463afa47cf2e7689431d3dd33e5b15cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sun, 30 Aug 2026 19:56:51 +0200 Subject: [PATCH] libc: Fix C23 version macro visibility In headers that existed prior to C23, these should be visible only in C23 or BSD mode. Fixes: 0fe73dcf7c32 ("libc: Add C23 feature test macro") Fixes: 1f09e354297c ("sys/limits.h: Add BOOL_MAX, BITINT_MAXWIDTH, and C23 feature test macro") Fixes: cd0727ec709b ("libc: Add C23 feature test macro") Fixes: fc9d02cb29ed ("libc: Add C23 feature test macro") Fixes: 4aeed6e9d213 ("libc: Add C23 feature test macro") Reviewed by: fuz, kfv, dteske Differential Revision: https://reviews.freebsd.org/D59272 --- include/assert.h | 2 ++ include/limits.h | 6 ++++-- include/setjmp.h | 6 ++++-- include/stdio.h | 6 ++++-- include/time.h | 6 ++++-- sys/sys/stdatomic.h | 6 ++++-- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/assert.h b/include/assert.h index d474169719c6..06e771d24cf5 100644 --- a/include/assert.h +++ b/include/assert.h @@ -71,7 +71,9 @@ #ifndef _ASSERT_H_ #define _ASSERT_H_ +#if __ISO_C_VISIBLE >= 2023 || __BSD_VISIBLE #define __STDC_VERSION_ASSERT_H__ 202311L +#endif /* * Static assertions. In principle we could define static_assert for diff --git a/include/limits.h b/include/limits.h index 5e7e0317d42e..0ab58086cd2a 100644 --- a/include/limits.h +++ b/include/limits.h @@ -32,10 +32,12 @@ #ifndef _LIMITS_H_ #define _LIMITS_H_ -#define __STDC_VERSION_LIMITS_H__ 202311L - #include +#if __ISO_C_VISIBLE >= 2023 || __BSD_VISIBLE +#define __STDC_VERSION_LIMITS_H__ 202311L +#endif + #if __POSIX_VISIBLE #define _POSIX_ARG_MAX 4096 #define _POSIX_LINK_MAX 8 diff --git a/include/setjmp.h b/include/setjmp.h index 108b47771160..45a3beeec6ec 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -37,10 +37,12 @@ #ifndef _SETJMP_H_ #define _SETJMP_H_ -#define __STDC_VERSION_SETJMP_H__ 202311L - #include +#if __ISO_C_VISIBLE >= 2023 || __BSD_VISIBLE +#define __STDC_VERSION_SETJMP_H__ 202311L +#endif + /* The size of the jmp_buf is machine dependent: */ #include diff --git a/include/stdio.h b/include/stdio.h index 566dddb76925..1c7b0b3d0e8b 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -35,12 +35,14 @@ #ifndef _STDIO_H_ #define _STDIO_H_ -#define __STDC_VERSION_STDIO_H__ 202311L - #include #include #include +#if __ISO_C_VISIBLE >= 2023 || __BSD_VISIBLE +#define __STDC_VERSION_STDIO_H__ 202311L +#endif + __NULLABILITY_PRAGMA_PUSH typedef __off_t fpos_t; diff --git a/include/time.h b/include/time.h index fed2805e03f1..6b304b6dd03b 100644 --- a/include/time.h +++ b/include/time.h @@ -37,13 +37,15 @@ #ifndef _TIME_H_ #define _TIME_H_ -#define __STDC_VERSION_TIME_H__ 202311L - #include #include #include #include +#if __ISO_C_VISIBLE >= 2023 || __BSD_VISIBLE +#define __STDC_VERSION_TIME_H__ 202311L +#endif + #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE /* * Frequency of the clock ticks reported by times(). Deprecated - use diff --git a/sys/sys/stdatomic.h b/sys/sys/stdatomic.h index cc1e31f658a4..e57fe3538bea 100644 --- a/sys/sys/stdatomic.h +++ b/sys/sys/stdatomic.h @@ -30,11 +30,13 @@ #ifndef _STDATOMIC_H_ #define _STDATOMIC_H_ -#define __STDC_VERSION_STDATOMIC_H__ 202311L - #include #include +#if __ISO_C_VISIBLE >= 2023 || __BSD_VISIBLE +#define __STDC_VERSION_STDATOMIC_H__ 202311L +#endif + #if (__has_extension(c_atomic) || __has_extension(cxx_atomic)) && \ defined(__clang__) #define __CLANG_ATOMICS