git: 4afcb821938f - main - cdefs: Support _ISOC23_SOURCE and --std=c23
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 15 Nov 2024 02:02:08 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=4afcb821938f5e8cb50e3a781f0276c4f5357b1a
commit 4afcb821938f5e8cb50e3a781f0276c4f5357b1a
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-11-14 23:52:35 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-11-15 01:58:17 +0000
cdefs: Support _ISOC23_SOURCE and --std=c23
If either _ISOC23_SOURCE is defined or --std=c23 (or higher) is
specified, then default to the making the ISO C visibility to 2023.
This mirrors what glibc does, so update the comment for this change to
_ISOCxx_SOURCE values. We currently implement xx = 11 or 23. C17 added
no new defines or symbols, so we follow glibc's lead and ommit it.
However, we don't implement the C95, C99 or C2y versions. These are
non-standard and the first two don't seem to be relevant, and the latter
is also experimental.
Sponsored by: Netflix
Reviewed by: brooks
Differential Revision: https://reviews.freebsd.org/D47576
---
sys/sys/cdefs.h | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 25248bd235b2..1a1705129fa6 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -567,14 +567,21 @@
#define __POSIX_VISIBLE 198808
#define __ISO_C_VISIBLE 0
#endif /* _POSIX_C_SOURCE */
+
/*
- * Both glibc and OpenBSD enable c11 features when _ISOC11_SOURCE is defined, or
- * when compiling with -stdc=c11. A strict reading of the standard would suggest
- * doing it only for the former. However, a strict reading also requires C99
- * mode only, so building with C11 is already undefined. Follow glibc's and
- * OpenBSD's lead for this non-standard configuration for maximum compatibility.
+ * When we've explicitly asked for a newer C version, make the C variable
+ * visible by default. Also honor the glibc _ISOC{11,23}_SOURCE macros
+ * extensions. Both glibc and OpenBSD do this, even when a more strict
+ * _POSIX_C_SOURCE has been requested, and it makes good sense (especially for
+ * pre POSIX 2024, since C11 is much nicer than the old C99 base). Continue the
+ * practice with C23, though don't do older standards. Also, GLIBC doesn't have
+ * a _ISOC17_SOURCE, so it's not implemented here. glibc has earlier ISOCxx defines,
+ * but we don't implement those as they are not relevant enough.
*/
-#if _ISOC11_SOURCE || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
+#if _ISOC23_SOURCE || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
+#undef __ISO_C_VISIBLE
+#define __ISO_C_VISIBLE 2023
+#elif _ISOC11_SOURCE || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
#undef __ISO_C_VISIBLE
#define __ISO_C_VISIBLE 2011
#endif