[PATCH v1 03/35] Assume __GNUC__ >= 3

Alejandro Colomar alx@kernel.org
Sun Nov 9 21:52:52 GMT 2025


Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 assert/assert.h                               | 13 +---
 dlfcn/dlfcn.h                                 |  4 -
 include/features.h                            |  2 +-
 include/intprops.h                            |  7 --
 include/libc-symbols.h                        | 14 ----
 malloc/obstack.h                              |  4 -
 math/complex.h                                |  7 --
 math/tgmath.h                                 |  5 --
 misc/sys/cdefs.h                              | 78 +------------------
 posix/bits/cpu-set.h                          | 24 ------
 posix/regex.h                                 | 10 ---
 posix/sys/types.h                             |  4 -
 socket/sys/socket.h                           |  2 +-
 sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h   |  2 +-
 sysdeps/unix/sysv/linux/s390/bits/typesizes.h |  5 --
 timezone/private.h                            | 13 +---
 16 files changed, 10 insertions(+), 184 deletions(-)

diff --git a/assert/assert.h b/assert/assert.h
index 273bf7f35c..32ef0634cc 100644
--- a/assert/assert.h
+++ b/assert/assert.h
@@ -34,7 +34,7 @@
 #define	_ASSERT_H	1
 #include <features.h>
 
-#if defined __cplusplus && __GNUC_PREREQ (2,95)
+#if defined __cplusplus
 # define __ASSERT_VOID_CAST static_cast<void>
 #else
 # define __ASSERT_VOID_CAST (void)
@@ -128,20 +128,11 @@ __END_DECLS
    : __assert_perror_fail ((errnum), __FILE__, __LINE__, __ASSERT_FUNCTION))
 # endif
 
-/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
+/* GCC defines a magical variable `__PRETTY_FUNCTION__'
    which contains the name of the function currently being defined.
-   This is broken in G++ before version 2.6.
    C9x has a similar variable called __func__, but prefer the GCC one since
    it demangles C++ function names.  */
-# if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
 #   define __ASSERT_FUNCTION	__extension__ __PRETTY_FUNCTION__
-# else
-#  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
-#   define __ASSERT_FUNCTION	__func__
-#  else
-#   define __ASSERT_FUNCTION	((const char *) 0)
-#  endif
-# endif
 
 #endif /* NDEBUG.  */
 
diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index bc73180a20..e266f1ab00 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -185,7 +185,6 @@ typedef struct
 {
   size_t dls_size;		/* Size in bytes of the whole buffer.  */
   unsigned int dls_cnt;		/* Number of elements in `dls_serpath'.  */
-# if __GNUC_PREREQ (3, 0)
   /* The zero-length array avoids an unwanted array subscript check by
      the compiler, while the surrounding anonymous union preserves the
      historic size of the type.  At the time of writing, GNU C does
@@ -195,9 +194,6 @@ typedef struct
     Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements.  */
     Dl_serpath __dls_serpath_pad[1];
   };
-# else
-  Dl_serpath dls_serpath[1];	/* Actually longer, dls_cnt elements.  */
-# endif
 } Dl_serinfo;
 
 struct dl_find_object
diff --git a/include/features.h b/include/features.h
index 877d4c7aa8..7d8095c682 100644
--- a/include/features.h
+++ b/include/features.h
@@ -534,7 +534,7 @@
 #endif	/* !ASSEMBLER */
 
 /* Decide whether we can define 'extern inline' functions in headers.  */
-#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
+#if defined __OPTIMIZE__ \
     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
     && defined __extern_inline && !(defined __clang__ && defined _LIBC)
 # define __USE_EXTERN_INLINES	1
diff --git a/include/intprops.h b/include/intprops.h
index 126d661156..377706ac3d 100644
--- a/include/intprops.h
+++ b/include/intprops.h
@@ -84,14 +84,7 @@
 
 /* Does the __typeof__ keyword work?  This could be done by
    'configure', but for now it's easier to do it by hand.  */
-#if (2 <= __GNUC__ \
-     || (4 <= __clang_major__) \
-     || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
-     || (0x5110 <= __SUNPRO_C && !__STDC__))
 # define _GL_HAVE___TYPEOF__ 1
-#else
-# define _GL_HAVE___TYPEOF__ 0
-#endif
 
 /* Return 1 if the integer type or expression T might be signed.  Return 0
    if it is definitely unsigned.  T must not be a bit-field expression.
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 2f9453e0d7..1f59b69ecf 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -813,11 +813,7 @@ for linking")
 /* Define as a marker that can be attached to declarations that might not
     be used.  This helps to reduce warnings, such as from
     GCC -Wunused-parameter.  */
-#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
 # define _GL_UNUSED __attribute__ ((__unused__))
-#else
-# define _GL_UNUSED
-#endif
 
 /* gcc supports the "unused" attribute on possibly unused labels, and
    g++ has since version 4.5.  Note to support C++ as well as C,
@@ -829,19 +825,9 @@ for linking")
 # define _GL_UNUSED_LABEL
 #endif
 
-/* The __pure__ attribute was added in gcc 2.96.  */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
-#else
-# define _GL_ATTRIBUTE_PURE /* empty */
-#endif
 
-/* The __const__ attribute was added in gcc 2.95.  */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
-#else
-# define _GL_ATTRIBUTE_CONST /* empty */
-#endif
 
 #endif /* !_ISOMAC */
 #endif /* libc-symbols.h */
diff --git a/malloc/obstack.h b/malloc/obstack.h
index 43457353c3..5b913047e3 100644
--- a/malloc/obstack.h
+++ b/malloc/obstack.h
@@ -257,10 +257,6 @@ extern int obstack_exit_failure;
 
 #define obstack_memory_used(h) _obstack_memory_used (h)
 
-# if ! (2 < __GNUC__ + (8 <= __GNUC_MINOR__))
-#  define __extension__
-# endif
-
 /* For GNU C, if not -traditional,
    we can define these macros to compute all args only once
    without using a global variable.
diff --git a/math/complex.h b/math/complex.h
index c925c5c0a3..2e542eb1e0 100644
--- a/math/complex.h
+++ b/math/complex.h
@@ -33,13 +33,6 @@
 
 __BEGIN_DECLS
 
-/* We might need to add support for more compilers here.  But since ISO
-   C99 is out hopefully all maintained compilers will soon provide the data
-   types `float complex' and `double complex'.  */
-#if __GNUC_PREREQ (2, 7) && !__GNUC_PREREQ (2, 97)
-# define _Complex __complex__
-#endif
-
 #define complex		_Complex
 
 /* Narrowest imaginary unit.  This depends on the floating-point
diff --git a/math/tgmath.h b/math/tgmath.h
index 0d830a713b..098760071f 100644
--- a/math/tgmath.h
+++ b/math/tgmath.h
@@ -49,8 +49,6 @@
 #define __HAVE_BUILTIN_TGMATH __GNUC_PREREQ (8, 0)
 #define __HAVE_BUILTIN_TGMATH_C23 __GNUC_PREREQ (13, 0)
 
-#if __GNUC_PREREQ (2, 7)
-
 /* Certain cases of narrowing macros only need to call a single
    function so cannot use __builtin_tgmath and do not need any
    complicated logic.  */
@@ -791,9 +789,6 @@
   (F ## f64 (X, Y, Z))
 #  endif
 # endif
-#else
-# error "Unsupported compiler; you cannot use <tgmath.h>"
-#endif
 
 
 /* Unary functions defined for real and complex values.  */
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 71e2ec92d5..da6ef07a4a 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -79,7 +79,7 @@
 #  define __NTH(fct)	__attribute__ ((__nothrow__ __LEAF)) fct
 #  define __NTHNL(fct)  __attribute__ ((__nothrow__)) fct
 # else
-#  if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
+#  if defined __cplusplus
 #   if __cplusplus >= 201103L
 #    define __THROW	noexcept (true)
 #   else
@@ -360,16 +360,11 @@
 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
 # define __flexarr	[]
 # define __glibc_c99_flexarr_available 1
-#elif __GNUC_PREREQ (2,97) || defined __clang__
-/* GCC 2.97 and clang support C99 flexible array members as an extension,
+#else
+/* GCC and clang support C99 flexible array members as an extension,
    even when in C89 mode or compiling C++ (any version).  */
 # define __flexarr	[]
 # define __glibc_c99_flexarr_available 1
-#else
-/* Pre-2.97 GCC did not support C99 flexible arrays but did have
-   an equivalent extension with slightly different notation.  */
-# define __flexarr	[0]
-# define __glibc_c99_flexarr_available 1
 #endif
 
 
@@ -406,14 +401,7 @@
 #define __REDIRECT_FORTIFY_NTH __REDIRECT_NTH
 #endif
 
-/* At some point during the gcc 2.96 development the `malloc' attribute
-   for functions was introduced.  We don't want to use it unconditionally
-   (although this would be possible) since it generates warnings.  */
-#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
 # define __attribute_malloc__ __attribute__ ((__malloc__))
-#else
-# define __attribute_malloc__ /* Ignore */
-#endif
 
 /* Tell the compiler which arguments to an allocation function
    indicate the size of the allocation.  */
@@ -433,27 +421,12 @@
 # define __attribute_alloc_align__(param) /* Ignore.  */
 #endif
 
-/* At some point during the gcc 2.96 development the `pure' attribute
-   for functions was introduced.  We don't want to use it unconditionally
-   (although this would be possible) since it generates warnings.  */
-#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
 # define __attribute_pure__ __attribute__ ((__pure__))
-#else
-# define __attribute_pure__ /* Ignore */
-#endif
 
 /* This declaration tells the compiler that the value is constant.  */
-#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
 # define __attribute_const__ __attribute__ ((__const__))
-#else
-# define __attribute_const__ /* Ignore */
-#endif
 
-#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
 # define __attribute_maybe_unused__ __attribute__ ((__unused__))
-#else
-# define __attribute_maybe_unused__ /* Ignore */
-#endif
 
 /* At some point during the gcc 3.1 development the `used' attribute
    for functions was introduced.  We don't want to use it unconditionally
@@ -484,28 +457,13 @@
 # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
 #endif
 
-/* At some point during the gcc 2.8 development the `format_arg' attribute
-   for functions was introduced.  We don't want to use it unconditionally
-   (although this would be possible) since it generates warnings.
-   If several `format_arg' attributes are given for the same function, in
+/* If several `format_arg' attributes are given for the same function, in
    gcc-3.0 and older, all but the last one are ignored.  In newer gccs,
    all designated arguments are considered.  */
-#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
-#else
-# define __attribute_format_arg__(x) /* Ignore */
-#endif
 
-/* At some point during the gcc 2.97 development the `strfmon' format
-   attribute for functions was introduced.  We don't want to use it
-   unconditionally (although this would be possible) since it
-   generates warnings.  */
-#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
 # define __attribute_format_strfmon__(a,b) \
   __attribute__ ((__format__ (__strfmon__, a, b)))
-#else
-# define __attribute_format_strfmon__(a,b) /* Ignore */
-#endif
 
 /* The nonnull function attribute marks pointer parameters that
    must not be NULL.  This has the name __nonnull in glibc,
@@ -600,25 +558,6 @@
 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
 #endif
 
-/* It is possible to compile containing GCC extensions even if GCC is
-   run in pedantic mode if the uses are carefully marked using the
-   `__extension__' keyword.  But this is not generally available before
-   version 2.8.  */
-#if !(__GNUC_PREREQ (2,8) || defined __clang__)
-# define __extension__		/* Ignore */
-#endif
-
-/* __restrict is known in EGCS 1.2 and above, and in clang.
-   It works also in C++ mode (outside of arrays), but only when spelled
-   as '__restrict', not 'restrict'.  */
-#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
-# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
-#  define __restrict	restrict
-# else
-#  define __restrict	/* Ignore */
-# endif
-#endif
-
 /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
      array_name[restrict]
    GCC 3.1 and clang support this.
@@ -629,23 +568,14 @@
 #  define __restrict_arr	/* Not supported in old GCC.  */
 #endif
 
-#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
 # define __glibc_unlikely(cond)	__builtin_expect ((cond), 0)
 # define __glibc_likely(cond)	__builtin_expect ((cond), 1)
-#else
-# define __glibc_unlikely(cond)	(cond)
-# define __glibc_likely(cond)	(cond)
-#endif
 
 #if (!defined _Noreturn \
      && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
      &&  !(__GNUC_PREREQ (4,7) \
            || (3 < __clang_major__ + (5 <= __clang_minor__))))
-# if __GNUC_PREREQ (2,8)
 #  define _Noreturn __attribute__ ((__noreturn__))
-# else
-#  define _Noreturn
-# endif
 #endif
 
 #if __GNUC_PREREQ (8, 0)
diff --git a/posix/bits/cpu-set.h b/posix/bits/cpu-set.h
index 9dc2d31fa7..c76a6de436 100644
--- a/posix/bits/cpu-set.h
+++ b/posix/bits/cpu-set.h
@@ -42,19 +42,8 @@ typedef struct
 } cpu_set_t;
 
 /* Access functions for CPU masks.  */
-#if __GNUC_PREREQ (2, 91)
 # define __CPU_ZERO_S(setsize, cpusetp) \
   do __builtin_memset (cpusetp, '\0', setsize); while (0)
-#else
-# define __CPU_ZERO_S(setsize, cpusetp) \
-  do {									      \
-    size_t __i;								      \
-    size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
-    __cpu_mask *__bits = (cpusetp)->__bits;				      \
-    for (__i = 0; __i < __imax; ++__i)					      \
-      __bits[__i] = 0;							      \
-  } while (0)
-#endif
 #define __CPU_SET_S(cpu, setsize, cpusetp) \
   (__extension__							      \
    ({ size_t __cpu = (cpu);						      \
@@ -80,21 +69,8 @@ typedef struct
 #define __CPU_COUNT_S(setsize, cpusetp) \
   __sched_cpucount (setsize, cpusetp)
 
-#if __GNUC_PREREQ (2, 91)
 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
   (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
-#else
-# define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
-  (__extension__							      \
-   ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits;			      \
-      const __cpu_mask *__arr2 = (cpusetp2)->__bits;			      \
-      size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
-      size_t __i;							      \
-      for (__i = 0; __i < __imax; ++__i)				      \
-	if (__arr1[__i] != __arr2[__i])					      \
-	  break;							      \
-      __i == __imax; }))
-#endif
 
 #define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
   (__extension__							      \
diff --git a/posix/regex.h b/posix/regex.h
index a7b66a2bfb..4facb457b1 100644
--- a/posix/regex.h
+++ b/posix/regex.h
@@ -643,17 +643,7 @@ extern int re_exec (const char *);
    'configure' might #define 'restrict' to those words, so pick a
    different name.  */
 #ifndef _Restrict_
-# if defined __restrict \
-     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
-     || __clang_major__ >= 3
 #  define _Restrict_ __restrict
-# else
-#  if 199901L <= __STDC_VERSION__ || defined restrict
-#   define _Restrict_ restrict
-#  else
-#   define _Restrict_
-#  endif
-# endif
 #endif
 /* For the ISO C99 syntax
      array_name[restrict]
diff --git a/posix/sys/types.h b/posix/sys/types.h
index ab3037a9da..30e0e88928 100644
--- a/posix/sys/types.h
+++ b/posix/sys/types.h
@@ -160,11 +160,7 @@ typedef __uint16_t u_int16_t;
 typedef __uint32_t u_int32_t;
 typedef __uint64_t u_int64_t;
 
-#if __GNUC_PREREQ (2, 7)
 typedef int register_t __attribute__ ((__mode__ (__word__)));
-#else
-typedef int register_t;
-#endif
 
 /* Some code from BIND tests this macro to see if the types above are
    defined.  */
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index e72f5e722e..905bf167bd 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -54,7 +54,7 @@ enum
    uses with any of the listed types to be allowed without complaint.
    G++ 2.7 does not support transparent unions so there we want the
    old-style declaration, too.  */
-#if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
+#if defined __cplusplus || !defined __USE_GNU
 # define __SOCKADDR_ARG		struct sockaddr *__restrict
 # define __CONST_SOCKADDR_ARG	const struct sockaddr *
 #else
diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
index 40415aae80..2cbc736a25 100644
--- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
+++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
@@ -64,7 +64,7 @@ struct riscv_hwprobe {
 
 __BEGIN_DECLS
 
-#if defined __cplusplus || !__GNUC_PREREQ (2, 7)
+#if defined __cplusplus
 # define __RISCV_HWPROBE_CPUS_TYPE cpu_set_t *
 #else
 /* The fourth argument to __riscv_hwprobe should be a null pointer or a
diff --git a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
index 3ad7986ba6..8d290d6e09 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -57,13 +57,8 @@
 #define __TIMER_T_TYPE		void *
 #define __BLKSIZE_T_TYPE	__SLONGWORD_TYPE
 #define __FSID_T_TYPE		struct { int __val[2]; }
-#if __GNUC__ <= 2
-/* Compatibility with g++ 2.95.x.  */
-#define __SSIZE_T_TYPE		__SWORD_TYPE
-#else
 /* size_t is unsigned long int on s390 -m31.  */
 #define __SSIZE_T_TYPE		__SLONGWORD_TYPE
-#endif
 #define __SYSCALL_SLONG_TYPE	__SLONGWORD_TYPE
 #define __SYSCALL_ULONG_TYPE	__ULONGWORD_TYPE
 #define __CPU_MASK_TYPE 	__ULONGWORD_TYPE
diff --git a/timezone/private.h b/timezone/private.h
index 278cf25a0b..c7150f349b 100644
--- a/timezone/private.h
+++ b/timezone/private.h
@@ -523,11 +523,7 @@ typedef unsigned long uintmax_t;
 # endif
 #endif
 #ifndef ATTRIBUTE_MAYBE_UNUSED
-# if 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
 #  define ATTRIBUTE_MAYBE_UNUSED __attribute__((unused))
-# else
-#  define ATTRIBUTE_MAYBE_UNUSED /* empty */
-# endif
 #endif
 
 #if HAVE___HAS_C_ATTRIBUTE
@@ -538,10 +534,8 @@ typedef unsigned long uintmax_t;
 #ifndef ATTRIBUTE_NORETURN
 # if 201112 <= __STDC_VERSION__
 #  define ATTRIBUTE_NORETURN _Noreturn
-# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
-#  define ATTRIBUTE_NORETURN __attribute__((noreturn))
 # else
-#  define ATTRIBUTE_NORETURN /* empty */
+#  define ATTRIBUTE_NORETURN __attribute__((noreturn))
 # endif
 #endif
 
@@ -557,13 +551,8 @@ typedef unsigned long uintmax_t;
 /* GCC attributes that are useful in tzcode.
    __attribute__((pure)) is stricter than [[reproducible]],
    so the latter is an adequate substitute in non-GCC C23 platforms.  */
-#if __GNUC__ < 3
-# define ATTRIBUTE_FORMAT(spec) /* empty */
-# define ATTRIBUTE_PURE ATTRIBUTE_REPRODUCIBLE
-#else
 # define ATTRIBUTE_FORMAT(spec) __attribute__((format spec))
 # define ATTRIBUTE_PURE __attribute__((pure))
-#endif
 
 /* Avoid GCC bug 114833 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114833>.
    Remove this macro and its uses when the bug is fixed in a GCC release,
-- 
2.51.0



More information about the Libc-alpha mailing list