sys/features.h: Define _ISOC2Y_SOURCE and __ISO_C_VISIBLE

Message ID 20241029143445.71886-2-newlib@lenardmollenkopf.de
State New
Headers
Series sys/features.h: Define _ISOC2Y_SOURCE and __ISO_C_VISIBLE |

Commit Message

Lenard Mollenkopf Oct. 29, 2024, 2:34 p.m. UTC
  Add feature test for C2Y code. Add matching definitions
_ISOC2Y_SOURCE for requesting sources and __ISO_C_VISIBLE
to be used in headers.

Signed-off-by: Lenard Mollenkopf <newlib@lenardmollenkopf.de>
---
 newlib/libc/include/sys/features.h | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
  

Comments

Corinna Vinschen Oct. 29, 2024, 3:10 p.m. UTC | #1
Hi Lenard,

thanks, but... shouldn't we first redefine _ISOC2X_SOURCE to
_ISOC23_SOURCE (keeping _ISOC2X_SOURCE for backward compat),
handle __STDC_VERSION__ >= 202311L if necessary, and only then
add _ISOC2Y_SOURCE?

From the clang user guide I take it that the differences between c23
and c2y are negligible, but that would be in the light of keeping
compatibility with gcc and glibc in terms of feature tests.

As far as _ISOC2Y_SOURCE is concerned, it's not yet supported by
glibc, either, right?  Your patch at
https://patchwork.sourceware.org/project/glibc/patch/20241022131752.15971-1-glibc@lenardmollenkopf.de/
has not been merged yet, afaics.

On Oct 29 15:34, Lenard Mollenkopf wrote:
> @@ -232,6 +237,11 @@ extern "C" {
>   *	g++ -std=c++20 or newer, or with
>   *	_ISOC2X_SOURCE.
>   *
> + * __ISO_C_VISIBLE >= 2024
> + *	ISO C2y; enabled with gcc -std=c2y or newer,
> + *	g++ -std=c++26 or newer, or with
> + *	_ISOC2y_SOURCE.
> + *
>   * __ATFILE_VISIBLE
>   *	"at" functions; enabled by default, with _ATFILE_SOURCE,
>   *	_POSIX_C_SOURCE >= 200809L, or _XOPEN_SOURCE >= 700.
> @@ -278,7 +288,10 @@ extern "C" {

In between here, if _GNU_SOURCE is defined, _ISOC2Y_SOURCE should be
defined as well.


>  #define	__GNU_VISIBLE		0
>  #endif
>  
> -#if defined(_ISOC2X_SOURCE) || \
> +#if defined(_ISOC2Y_SOURCE) || \
> +  (__STDC_VERSION__ - 0) >= 202400L || (__cplusplus - 0) >= 202400L
> +#define __ISO_C_VISIBLE		2024
> +#elif defined(_ISOC2X_SOURCE) || \
>    (__STDC_VERSION__ - 0) > 201710L || (__cplusplus - 0) >= 202002L
>  #define __ISO_C_VISIBLE		2020
>  #elif defined(_ISOC11_SOURCE) || \
> -- 
> 2.47.0

Thanks,
Corinna
  

Patch

diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h
index 00c3bba9c..3fc5d87a7 100644
--- a/newlib/libc/include/sys/features.h
+++ b/newlib/libc/include/sys/features.h
@@ -93,6 +93,9 @@  extern "C" {
  * _ISOC2x_SOURCE or gcc -std=c2x or g++ -std=c++20
  *	ISO C2x
  *
+ * _ISOC2y_SOURCE or gcc -std=c2y or g++ -std=c++26
+ *	ISO C2y
+ *
  * _ATFILE_SOURCE (implied by _POSIX_C_SOURCE >= 200809L)
  *	"at" functions
  *
@@ -122,6 +125,8 @@  extern "C" {
 #define	_ISOC11_SOURCE		1
 #undef _ISOC2X_SOURCE
 #define	_ISOC2X_SOURCE		1
+#undef _ISOC2Y_SOURCE
+#define	_ISOC2Y_SOURCE		1
 #undef _POSIX_SOURCE
 #define	_POSIX_SOURCE		1
 #undef _POSIX_C_SOURCE
@@ -232,6 +237,11 @@  extern "C" {
  *	g++ -std=c++20 or newer, or with
  *	_ISOC2X_SOURCE.
  *
+ * __ISO_C_VISIBLE >= 2024
+ *	ISO C2y; enabled with gcc -std=c2y or newer,
+ *	g++ -std=c++26 or newer, or with
+ *	_ISOC2y_SOURCE.
+ *
  * __ATFILE_VISIBLE
  *	"at" functions; enabled by default, with _ATFILE_SOURCE,
  *	_POSIX_C_SOURCE >= 200809L, or _XOPEN_SOURCE >= 700.
@@ -278,7 +288,10 @@  extern "C" {
 #define	__GNU_VISIBLE		0
 #endif
 
-#if defined(_ISOC2X_SOURCE) || \
+#if defined(_ISOC2Y_SOURCE) || \
+  (__STDC_VERSION__ - 0) >= 202400L || (__cplusplus - 0) >= 202400L
+#define __ISO_C_VISIBLE		2024
+#elif defined(_ISOC2X_SOURCE) || \
   (__STDC_VERSION__ - 0) > 201710L || (__cplusplus - 0) >= 202002L
 #define __ISO_C_VISIBLE		2020
 #elif defined(_ISOC11_SOURCE) || \