In a testdir of fts and the GCC 15 warnings from HACKING I see:

    $ cat ../output.txt 
      CC       fts.o
    In file included from /usr/include/features.h:524,
                     from /usr/include/sys/types.h:25,
                     from ./sys/types.h:46,
                     from fts_.h:80,
                     from fts.c:53:
    /usr/include/sys/cdefs.h:79:11: warning: '__THROW' redefined
       79 | #  define __THROW       __attribute__ ((__nothrow__ __LEAF))
          |           ^~~~~~~
    fts_.h:67:11: note: this is the location of the previous definition
       67 | #  define __THROW
          |           ^~~~~~~

This is because fts_.h checks and undefines __THROW before <sys/cdefs.h>
is included in fts.c.

I have pushed the attached patch which fixes that and defines the macros
correctly like in getopt-cdefs.in.h as opposed to just undefining them.

Collin

>From 4cfd636f65174efdecfe01b864878c1502b21640 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sat, 10 May 2025 16:07:57 -0700
Subject: [PATCH] fts: Fix redefinition of __THROW.

* lib/fts_.h: Include <sys/cdefs.h> if the system has it.
(__THROW, __BEGIN_DECLS, __END_DECLS): Define properly if not previously
defined.
* m4/fts.m4 (gl_FUNC_FTS_CORE): Check for sys/cdefs.h.
---
 ChangeLog  |  8 ++++++++
 lib/fts_.h | 37 +++++++++++++++++++++++++++----------
 m4/fts.m4  |  3 ++-
 3 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2d7696a717..6c248f533a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-05-10  Collin Funk  <collin.fu...@gmail.com>
+
+	fts: Fix redefinition of __THROW.
+	* lib/fts_.h: Include <sys/cdefs.h> if the system has it.
+	(__THROW, __BEGIN_DECLS, __END_DECLS): Define properly if not previously
+	defined.
+	* m4/fts.m4 (gl_FUNC_FTS_CORE): Check for sys/cdefs.h.
+
 2025-05-10  Bruno Haible  <br...@clisp.org>
 
 	string-desc, xstring-desc: Avoid GCC attributes in function definitions.
diff --git a/lib/fts_.h b/lib/fts_.h
index 9fb4c62df9..052858da7b 100644
--- a/lib/fts_.h
+++ b/lib/fts_.h
@@ -62,17 +62,34 @@
 #   define __FLEXIBLE_ARRAY_MEMBER
 #  endif
 # else
+#  if HAVE_SYS_CDEFS_H
+#   include <sys/cdefs.h>
+#  endif
 #  define __FLEXIBLE_ARRAY_MEMBER FLEXIBLE_ARRAY_MEMBER
-#  undef __THROW
-#  define __THROW
-#  undef __BEGIN_DECLS
-#  undef __END_DECLS
-#  ifdef __cplusplus
-#   define __BEGIN_DECLS extern "C" {
-#   define __END_DECLS }
-#  else
-#   define __BEGIN_DECLS
-#   define __END_DECLS
+#  ifndef __THROW
+#   if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
+#    if __cplusplus >= 201103L
+#     define __THROW      noexcept (true)
+#    else
+#     define __THROW      throw ()
+#    endif
+#   else
+#    define __THROW
+#   endif
+#  endif
+#  ifndef __BEGIN_DECLS
+#   ifdef __cplusplus
+#    define __BEGIN_DECLS extern "C" {
+#   else
+#    define __BEGIN_DECLS /* nothing */
+#   endif
+#  endif
+#  ifndef __END_DECLS
+#   ifdef __cplusplus
+#    define __END_DECLS }
+#   else
+#    define __END_DECLS /* nothing */
+#   endif
 #  endif
 # endif
 
diff --git a/m4/fts.m4 b/m4/fts.m4
index 1c230bb93f..1d3a32f52e 100644
--- a/m4/fts.m4
+++ b/m4/fts.m4
@@ -1,5 +1,5 @@
 # fts.m4
-# serial 24
+# serial 25
 dnl Copyright (C) 2005-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_FTS_CORE]
 [
   dnl Prerequisites of lib/fts.c.
   gl_FUNC_OPENAT
+  AC_CHECK_HEADERS_ONCE([sys/cdefs.h])
 
   AC_CHECK_FUNCS_ONCE([fstatfs])
   AC_CHECK_HEADERS_ONCE([sys/param.h sys/vfs.h])dnl
-- 
2.49.0

Reply via email to