[PATCH] features.h: do not consider _GNU_SOURCE for gets

Arsen Arsenović arsen@aarsen.me
Sat Aug 15 22:18:45 GMT 2026


Currently, -std=c99 -D_GNU_SOURCE and similar lack the 'gets'
declaration.

This causes, say, programs using the:

  extern __typeof__ (gets) function __attribute__ ((__warning__ (...)))

... trick to add warnings to 'gets' use to break.  (_GL_WARN_ON_USE in
gnulib).

The decision not to declare 'gets' w/ _GNU_SOURCE is clearly intended
(see c3a87236702cb73be1dada3438bbd3c3934e83f8), but I don't see the
benefit in it (given that we already emit a diagnostic), and, as noted,
it does cause certain older versions of Gnulib to fail to compile
(which, in turn, causes multiple packages to fail to compile while
building), and no rationale was provided in the commit message.

It was not unreasonable for programs to assume that _GNU_SOURCE does not
remove declarations, I think.

So, let's keep it in -std=gnu99/c99 -D_GNU_SOURCE instead.

One test needed to ignore the 'gets' deprecation now, since it became
exposed to the deprecated declaration.
---
Tested on x86_64-linux-gnu.

Four failures that seem to be definitely unrelated (the GDB ones are a
GDB crash, the malloc one is a timeout, and tst-pthread-exited seems to
get EPERMs for some reason):

  ~/gnu/glibc/glibc/_b$ grep ^FAIL tests.sum
  FAIL: malloc/tst-malloc-tcache-leak-malloc-largetcache
  FAIL: nptl/tst-pthread-exited
  FAIL: nptl/tst-pthread-gdb-attach
  FAIL: nptl/tst-pthread-gdb-attach-static

I'd debug this normally, but it's getting late..

 include/features.h | 4 +++-
 libio/Makefile     | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/features.h b/include/features.h
index b3277f342cd6..a3f483fa7869 100644
--- a/include/features.h
+++ b/include/features.h
@@ -475,7 +475,9 @@
    safely.  It has been removed from ISO C11 and ISO C++14.  Note: for
    compatibility with various implementations of <cstdio>, this test
    must consider only the value of __cplusplus when compiling C++.  */
-#if defined __cplusplus ? __cplusplus >= 201402L : defined __USE_ISOC11
+#if (defined __cplusplus			\
+     ? __cplusplus >= 201402L			\
+     : (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L))
 # define __GLIBC_USE_DEPRECATED_GETS 0
 #else
 # define __GLIBC_USE_DEPRECATED_GETS 1
diff --git a/libio/Makefile b/libio/Makefile
index 616107ee105b..836a9dbb70d4 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -258,7 +258,7 @@ CFLAGS-oldtmpfile.c += -fexceptions
 
 # Prevent fortification as these are built with -O0
 CFLAGS-tst-bz24051.c += $(no-fortify-source)
-CFLAGS-tst-bz24153.c += $(no-fortify-source)
+CFLAGS-tst-bz24153.c += $(no-fortify-source) -Wno-deprecated-declarations
 
 CFLAGS-tst_putwc.c += -DOBJPFX=\"$(objpfx)\"
 
-- 
2.55.0



More information about the Libc-alpha mailing list