> > >   Fix compilation errors with clang that masquerades as gcc 13.
> > 
> > And here is a patch that fixes the clang warnings that appear to be caused
> > by this version of __GNUC__.
> 
> And here is a patch that avoids a test failure.

Other than that, I'm reviewing the other remaining occurrences of __GNUC__:

lib/_Noreturn.h:37:                && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
lib/aligned-malloc.h:67:# if defined aligned_free || __GNUC__ >= 11
lib/aligned-malloc.h:82:#  if defined aligned_malloc || __GNUC__ >= 11
lib/argp.h:47:# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) \
lib/arpa_inet.in.h:20:#if __GNUC__ >= 3
lib/assert.in.h:20:#if __GNUC__ >= 3
lib/astrxfrm.c:29:#if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4
lib/base32.h:30:#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
lib/base64.h:30:#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
lib/c++defs.h:317:# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
lib/cdefs.h:519:#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
lib/ctype.in.h:27:#if __GNUC__ >= 3
lib/dfa.c:83:# elif ((__GNUC__ >= 7) \
lib/dirent.in.h:155:#  if !@HAVE_OPENDIR@ || __GNUC__ >= 11
lib/dirent.in.h:165:# if @GNULIB_CLOSEDIR@ && !GNULIB_defined_DIR && __GNUC__ 
>= 11 && !defined opendir
lib/dirent.in.h:19:#if __GNUC__ >= 3
lib/dirent.in.h:277:#  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ || 
__GNUC__ >= 11
lib/dirent.in.h:286:# if @GNULIB_CLOSEDIR@ && __GNUC__ >= 11 && !defined 
fdopendir
lib/dirent.in.h:81:# if __GNUC__ >= 11
lib/endian.in.h:22:#if __GNUC__ >= 3
lib/errno.in.h:20:#if __GNUC__ >= 3
lib/fcntl.in.h:20:#if __GNUC__ >= 3
lib/fenv-private.h:136:# if __GNUC__ >= 6
lib/fenv-private.h:146:# if __GNUC__ >= 6
lib/fenv.in.h:20:#if __GNUC__ >= 3
lib/float.in.h:20:#if __GNUC__ >= 3
lib/fnmatch.in.h:22:#if __GNUC__ >= 3
lib/getopt.in.h:23:#if __GNUC__ >= 3
lib/gettext.h:55:#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 
3)
lib/glob.in.h:22:#if __GNUC__ >= 3
lib/glob.in.h:54:     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
lib/hamt.h:66:#if (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) \
lib/iconv.in.h:20:#if __GNUC__ >= 3
lib/intprops-internal.h:115:#elif 7 <= __GNUC__
lib/intprops-internal.h:139:# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
lib/intprops-internal.h:164:# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
lib/intprops-internal.h:24:#if defined __GNUC__ && 4 < __GNUC__ + (3 <= 
__GNUC_MINOR__)
lib/intprops-internal.h:80:#if (2 <= __GNUC__ \
lib/inttypes.in.h:23:#if __GNUC__ >= 3
lib/jit/cache.h:170:#elif (__GNUC__ + (__GNUC_MINOR__ >= 3) > 4) \
lib/langinfo.in.h:24:#if __GNUC__ >= 3
lib/libc-config.h:53:#  define __GNUC_PREREQ(maj, min) ((maj) < __GNUC__ + 
((min) <= __GNUC_MINOR__))
lib/limits.in.h:18:#if __GNUC__ >= 3
lib/locale.in.h:17:#if __GNUC__ >= 3
lib/malloc.in.h:151:#   if __GNUC__ >= 11
lib/malloc.in.h:173:# if __GNUC__ >= 11 && !defined memalign
lib/malloc.in.h:17:#if __GNUC__ >= 3
lib/math.in.h:25:#if __GNUC__ >= 3
lib/mcel.h:112:#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
lib/mntent.in.h:18:#if __GNUC__ >= 3
lib/monetary.in.h:19:#if __GNUC__ >= 3
lib/monetary.in.h:62:#elif __GNUC__ >= 3
lib/net_if.in.h:19:#if __GNUC__ >= 3
lib/netdb.in.h:24:#if __GNUC__ >= 3
lib/netinet_in.in.h:19:#if __GNUC__ >= 3
lib/noreturn.h:64:#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) 
\
lib/noreturn.h:97:#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) 
\
lib/omp.in.h:18:#if __GNUC__ >= 3
lib/poll.in.h:23:#if __GNUC__ >= 3
lib/pthread.in.h:20:#if __GNUC__ >= 3
lib/pty.in.h:19:#if __GNUC__ >= 3
lib/readutmp.c:151:#if 8 <= __GNUC__
lib/regex.h:534:#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
lib/regex.h:542:# elif defined __GNUC__ && 10 <= __GNUC__
lib/regex.h:647:     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
lib/regex.h:665:         || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
lib/regex.h:691:#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
lib/sched.in.h:19:#if __GNUC__ >= 3
lib/se-selinux.in.h:17:#if __GNUC__ >= 3
lib/search.in.h:20:#if __GNUC__ >= 3
lib/signal.in.h:18:#if __GNUC__ >= 3
lib/spawn.in.h:18:#if __GNUC__ >= 3
lib/spawn.in.h:76:     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
lib/spawn.in.h:94:         || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
lib/ssfmalloc.h:141:#if __GNUC__ >= 3
lib/stdalign.in.h:25:#if __GNUC__ >= 3
lib/stdarg.in.h:19:#if __GNUC__ >= 3
lib/stdbit.in.h:77:#if ((defined __GNUC__ && 2 <= __GNUC__) \
lib/stddef.in.h:197:#  elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
lib/stddef.in.h:25:#if __GNUC__ >= 3
lib/stdint.in.h:25:#if __GNUC__ >= 3
lib/stdio.in.h:123:# if __GNUC__ >= 11
lib/stdio.in.h:1251:#  if !@HAVE_POPEN@ || __GNUC__ >= 11
lib/stdio.in.h:1261:# if @GNULIB_PCLOSE@ && __GNUC__ >= 11 && !defined popen
lib/stdio.in.h:1670:#  if __GNUC__ >= 11
lib/stdio.in.h:1683:# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile
lib/stdio.in.h:18:#if __GNUC__ >= 3
lib/stdio.in.h:395:#  if __GNUC__ >= 11
lib/stdio.in.h:416:# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fdopen
lib/stdio.in.h:545:#  if __GNUC__ >= 11
lib/stdio.in.h:559:# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fopen
lib/stdio.in.h:954:       && 3 < __GNUC__ + (4 <= __GNUC_MINOR__)               
           \
lib/stdlib.in.h:135:# if __GNUC__ >= 11
lib/stdlib.in.h:1463:#  if __GNUC__ >= 11
lib/stdlib.in.h:1482:# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined 
realloc
lib/stdlib.in.h:18:#if __GNUC__ >= 3
lib/stdlib.in.h:303:#   if __GNUC__ >= 11
lib/stdlib.in.h:325:# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined 
aligned_alloc
lib/stdlib.in.h:379:#  if __GNUC__ >= 11
lib/stdlib.in.h:400:# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined 
calloc
lib/stdlib.in.h:433:#  if !@HAVE_CANONICALIZE_FILE_NAME@ || __GNUC__ >= 11
lib/stdlib.in.h:457:# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined 
canonicalize_file_name
lib/stdlib.in.h:692:#  if __GNUC__ >= 11
lib/stdlib.in.h:713:# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined 
malloc
lib/strftime.c:324:#if __GNUC__ >= 7 && !__OPTIMIZE__
lib/string.in.h:18:#if __GNUC__ >= 3
lib/string.in.h:624:#  if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined 
strdup
lib/string.in.h:642:# if __GNUC__ >= 11 && !defined strdup
lib/string.in.h:723:#  if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined 
strndup)
lib/string.in.h:741:# if __GNUC__ >= 11 && !defined strndup
lib/string.in.h:82:# if __GNUC__ >= 11
lib/strings.in.h:20:#if __GNUC__ >= 3
lib/strptime.c:45:#if defined _LIBC && defined __GNUC__ && __GNUC__ >= 2
lib/sys_file.in.h:22:#if __GNUC__ >= 3
lib/sys_ioctl.in.h:19:#if __GNUC__ >= 3
lib/sys_msg.in.h:18:#if __GNUC__ >= 3
lib/sys_random.in.h:17:# if __GNUC__ >= 3
lib/sys_resource.in.h:17:# if __GNUC__ >= 3
lib/sys_select.in.h:17:# if __GNUC__ >= 3
lib/sys_sem.in.h:18:#if __GNUC__ >= 3
lib/sys_shm.in.h:18:#if __GNUC__ >= 3
lib/sys_socket.in.h:25:#if __GNUC__ >= 3
lib/sys_stat.in.h:23:#if __GNUC__ >= 3
lib/sys_time.in.h:22:#if __GNUC__ >= 3
lib/sys_times.in.h:24:# if __GNUC__ >= 3
lib/sys_types.in.h:18:#if __GNUC__ >= 3
lib/sys_uio.in.h:17:# if __GNUC__ >= 3
lib/sys_un.in.h:22:#if __GNUC__ >= 3
lib/sys_utsname.in.h:19:#if __GNUC__ >= 3
lib/sys_wait.in.h:20:#if __GNUC__ >= 3
lib/sysexits.in.h:21:#if __GNUC__ >= 3
lib/termios.in.h:19:#if __GNUC__ >= 3
lib/threads.in.h:18:#if __GNUC__ >= 3
lib/time.in.h:18:#if __GNUC__ >= 3
lib/uchar.in.h:25:#if __GNUC__ >= 3
lib/unistd.in.h:19:#if __GNUC__ >= 3
lib/unitypes.in.h:56:     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
lib/utime.in.h:19:#if __GNUC__ >= 3
lib/utmp.in.h:18:#if __GNUC__ >= 3
lib/verify.h:218:# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
lib/verify.h:297:#elif 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= 
__GNUC_PATCHLEVEL__))
lib/verify.h:308:# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
lib/verify.h:41:      || (!defined __STRICT_ANSI__ && 9 <= __GNUC__))
lib/warn-on-use.h:101:# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
lib/warn-on-use.h:134:#  elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
lib/wchar.in.h:1329:#  if !@HAVE_WCSDUP@ || (defined __sun && defined 
__cplusplus) || __GNUC__ >= 11
lib/wchar.in.h:1345:# if __GNUC__ >= 11 && !defined wcsdup
lib/wchar.in.h:28:#if __GNUC__ >= 3
lib/wchar.in.h:98:# if __GNUC__ >= 11
lib/wctype.in.h:28:#if __GNUC__ >= 3
lib/xalloc-oversized.h:50:#elif 5 <= __GNUC__ && !defined __ICC && PTRDIFF_MAX 
< SIZE_MAX
m4/extern-inline.m4:94:#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined 
__STRICT_ANSI__ \
m4/gnulib-common.m4:1383:      #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
m4/stdalign.m4:108:       || (defined __GNUC__ && __GNUC__ < 4 + 
(__GNUC_MINOR__ < 9) \
m4/stdalign.m4:167:              ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
m4/stdalign.m4:48:                     ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
m4/stdint.m4:156:    && (!defined __GNUC__ || 4 < __GNUC__ + (9 <= 
__GNUC_MINOR__) \
modules/unitypes:22:     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
tests/from-glibc/tst-stdbit.h:52:#elif ((defined __GNUC__ && 2 <= __GNUC__) \
tests/test-asyncsafe-linked_list-strong.c:47:#if 4 < __GNUC__ + (3 <= 
__GNUC_MINOR__)
tests/test-asyncsafe-linked_list-weak.c:47:#if 4 < __GNUC__ + (3 <= 
__GNUC_MINOR__)
tests/test-c-strtod-mt.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-c-strtof-mt.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-c-strtold-mt.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-gmtime_r-mt.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-intprops.c:21:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-limits-h.c:23:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-localtime_r-mt.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-memrchr.c:31:#if 4 < __GNUC__ + (7 <= __GNUC_MINOR__) && __GNUC__ < 
12
tests/test-nl_langinfo-mt.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-setlocale_null-mt-all.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-setlocale_null-mt-one.c:22:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-statat.c:21:#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
tests/test-xvasprintf.c:20:#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < 
__GNUC__

and committing these two patches:


2024-08-27  Bruno Haible  <br...@clisp.org>

        Improve support for clang on Windows.
        * lib/c++defs.h (_GL_CXXALIASWARN_2): Treat clang like gcc 4.2.
        * lib/stdio.in.h (fwrite, fwrite_unlocked): Likewise.
        * lib/warn-on-use.h (_GL_WARN_ON_USE, _GL_WARN_ON_USE_CXX): Likewise.
        * lib/libc-config.h (__GNUC_PREREQ): Override glibc's definition to
        handle clang in disguise.

2024-08-27  Bruno Haible  <br...@clisp.org>

        Explicitly exclude clang when we test for a GCC version >= 4.3.
        Rationale: clang can disguise as any possible GCC version.
        * m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): When testing __GNUC__,
        exclude clang.
        * lib/_Noreturn.h (_Noreturn): Likewise.
        * lib/aligned-malloc.h (aligned_free, aligned_malloc): Likewise.
        * lib/base32.h: Likewise.
        * lib/base64.h: Likewise.
        * lib/dfa.c (FALLTHROUGH): Likewise.
        * lib/dirent.in.h (_GL_ATTRIBUTE_DEALLOC, opendir, fdopendir): Likewise.
        * lib/intprops-internal.h: Likewise.
        * lib/jit/cache.h (clear_cache): Likewise.
        * lib/malloc.in.h (memalign): Likewise.
        * lib/mcel.h: Likewise.
        * lib/regex.h: Likewise.
        * lib/stddef.in.h (_GL_HAS_BUILTIN_UNREACHABLE): Likewise.
        * lib/stdio.in.h (_GL_ATTRIBUTE_DEALLOC, fdopen, fopen, popen, tmpfile):
        Likewise.
        * lib/stdlib.in.h (_GL_ATTRIBUTE_DEALLOC, aligned_alloc, calloc,
        canonicalize_file_name, malloc, realloc): Likewise.
        * lib/string.in.h (_GL_ATTRIBUTE_DEALLOC, strdup, strndup): Likewise.
        * lib/verify.h: Likewise.
        * lib/wchar.in.h (_GL_ATTRIBUTE_DEALLOC, wcsdup): Likewise.
        * lib/xalloc-oversized.h (xalloc_oversized): Likewise.
        * lib/fenv-private.h (_FPU_GETCW, _FPU_SETCW, _FPU_GETFPSR,
        _FPU_SETFPSR): When testing __GNUC__, exclude clang. Use different
        builtins for clang.
        * lib/hamt.h (GL_HAMT_THREAD_SAFE): When testing __GNUC__, exclude
        clang. Enable for clang >= 4.
        * lib/astrxfrm.c: Use _GL_GNUC_PREREQ.
        * lib/readutmp.c: Likewise.
        * lib/strftime.c: Likewise.
        * tests/test-asyncsafe-linked_list-strong.c: Likewise.
        * tests/test-asyncsafe-linked_list-weak.c: Likewise.
        * tests/test-c-strtod-mt.c: Likewise.
        * tests/test-c-strtof-mt.c: Likewise.
        * tests/test-c-strtold-mt.c: Likewise.
        * tests/test-gmtime_r-mt.c: Likewise.
        * tests/test-intprops.c: Likewise.
        * tests/test-limits-h.c: Likewise.
        * tests/test-localtime_r-mt.c: Likewise.
        * tests/test-memrchr.c: Likewise.
        * tests/test-nl_langinfo-mt.c: Likewise.
        * tests/test-setlocale_null-mt-all.c: Likewise.
        * tests/test-setlocale_null-mt-one.c: Likewise.
        * tests/test-statat.c: Likewise.
        * tests/test-xvasprintf.c: Likewise.

>From 61720eb1b51d17dd672cbbbc9933f8e894c5b1a0 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 27 Aug 2024 16:20:16 +0200
Subject: [PATCH 1/2] Explicitly exclude clang when we test for a GCC version
 >= 4.3.

Rationale: clang can disguise as any possible GCC version.

* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): When testing __GNUC__,
exclude clang.
* lib/_Noreturn.h (_Noreturn): Likewise.
* lib/aligned-malloc.h (aligned_free, aligned_malloc): Likewise.
* lib/base32.h: Likewise.
* lib/base64.h: Likewise.
* lib/dfa.c (FALLTHROUGH): Likewise.
* lib/dirent.in.h (_GL_ATTRIBUTE_DEALLOC, opendir, fdopendir): Likewise.
* lib/intprops-internal.h: Likewise.
* lib/jit/cache.h (clear_cache): Likewise.
* lib/malloc.in.h (memalign): Likewise.
* lib/mcel.h: Likewise.
* lib/regex.h: Likewise.
* lib/stddef.in.h (_GL_HAS_BUILTIN_UNREACHABLE): Likewise.
* lib/stdio.in.h (_GL_ATTRIBUTE_DEALLOC, fdopen, fopen, popen, tmpfile):
Likewise.
* lib/stdlib.in.h (_GL_ATTRIBUTE_DEALLOC, aligned_alloc, calloc,
canonicalize_file_name, malloc, realloc): Likewise.
* lib/string.in.h (_GL_ATTRIBUTE_DEALLOC, strdup, strndup): Likewise.
* lib/verify.h: Likewise.
* lib/wchar.in.h (_GL_ATTRIBUTE_DEALLOC, wcsdup): Likewise.
* lib/xalloc-oversized.h (xalloc_oversized): Likewise.
* lib/fenv-private.h (_FPU_GETCW, _FPU_SETCW, _FPU_GETFPSR,
_FPU_SETFPSR): When testing __GNUC__, exclude clang. Use different
builtins for clang.
* lib/hamt.h (GL_HAMT_THREAD_SAFE): When testing __GNUC__, exclude
clang. Enable for clang >= 4.
* lib/astrxfrm.c: Use _GL_GNUC_PREREQ.
* lib/readutmp.c: Likewise.
* lib/strftime.c: Likewise.
* tests/test-asyncsafe-linked_list-strong.c: Likewise.
* tests/test-asyncsafe-linked_list-weak.c: Likewise.
* tests/test-c-strtod-mt.c: Likewise.
* tests/test-c-strtof-mt.c: Likewise.
* tests/test-c-strtold-mt.c: Likewise.
* tests/test-gmtime_r-mt.c: Likewise.
* tests/test-intprops.c: Likewise.
* tests/test-limits-h.c: Likewise.
* tests/test-localtime_r-mt.c: Likewise.
* tests/test-memrchr.c: Likewise.
* tests/test-nl_langinfo-mt.c: Likewise.
* tests/test-setlocale_null-mt-all.c: Likewise.
* tests/test-setlocale_null-mt-one.c: Likewise.
* tests/test-statat.c: Likewise.
* tests/test-xvasprintf.c: Likewise.
---
 ChangeLog                                 | 50 +++++++++++++++++++++++
 lib/_Noreturn.h                           |  2 +-
 lib/aligned-malloc.h                      |  4 +-
 lib/astrxfrm.c                            |  2 +-
 lib/base32.h                              |  2 +-
 lib/base64.h                              |  2 +-
 lib/dfa.c                                 |  2 +-
 lib/dirent.in.h                           | 13 +++---
 lib/fenv-private.h                        | 10 ++++-
 lib/hamt.h                                |  5 ++-
 lib/intprops-internal.h                   |  4 +-
 lib/jit/cache.h                           |  2 +-
 lib/malloc.in.h                           |  4 +-
 lib/mcel.h                                |  2 +-
 lib/readutmp.c                            |  2 +-
 lib/regex.h                               |  8 ++--
 lib/stddef.in.h                           |  2 +-
 lib/stdio.in.h                            | 20 +++++----
 lib/stdlib.in.h                           | 27 +++++++-----
 lib/strftime.c                            |  2 +-
 lib/string.in.h                           | 12 +++---
 lib/verify.h                              |  9 ++--
 lib/wchar.in.h                            |  7 ++--
 lib/xalloc-oversized.h                    |  3 +-
 m4/gnulib-common.m4                       | 14 +++----
 tests/test-asyncsafe-linked_list-strong.c |  2 +-
 tests/test-asyncsafe-linked_list-weak.c   |  2 +-
 tests/test-c-strtod-mt.c                  |  2 +-
 tests/test-c-strtof-mt.c                  |  2 +-
 tests/test-c-strtold-mt.c                 |  2 +-
 tests/test-gmtime_r-mt.c                  |  2 +-
 tests/test-intprops.c                     |  7 ++--
 tests/test-limits-h.c                     |  2 +-
 tests/test-localtime_r-mt.c               |  2 +-
 tests/test-memrchr.c                      |  2 +-
 tests/test-nl_langinfo-mt.c               |  2 +-
 tests/test-setlocale_null-mt-all.c        |  2 +-
 tests/test-setlocale_null-mt-one.c        |  2 +-
 tests/test-statat.c                       |  2 +-
 tests/test-xvasprintf.c                   |  6 +--
 40 files changed, 162 insertions(+), 87 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d46f8af16c..e372f307cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,53 @@
+2024-08-27  Bruno Haible  <br...@clisp.org>
+
+	Explicitly exclude clang when we test for a GCC version >= 4.3.
+	Rationale: clang can disguise as any possible GCC version.
+	* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): When testing __GNUC__,
+	exclude clang.
+	* lib/_Noreturn.h (_Noreturn): Likewise.
+	* lib/aligned-malloc.h (aligned_free, aligned_malloc): Likewise.
+	* lib/base32.h: Likewise.
+	* lib/base64.h: Likewise.
+	* lib/dfa.c (FALLTHROUGH): Likewise.
+	* lib/dirent.in.h (_GL_ATTRIBUTE_DEALLOC, opendir, fdopendir): Likewise.
+	* lib/intprops-internal.h: Likewise.
+	* lib/jit/cache.h (clear_cache): Likewise.
+	* lib/malloc.in.h (memalign): Likewise.
+	* lib/mcel.h: Likewise.
+	* lib/regex.h: Likewise.
+	* lib/stddef.in.h (_GL_HAS_BUILTIN_UNREACHABLE): Likewise.
+	* lib/stdio.in.h (_GL_ATTRIBUTE_DEALLOC, fdopen, fopen, popen, tmpfile):
+	Likewise.
+	* lib/stdlib.in.h (_GL_ATTRIBUTE_DEALLOC, aligned_alloc, calloc,
+	canonicalize_file_name, malloc, realloc): Likewise.
+	* lib/string.in.h (_GL_ATTRIBUTE_DEALLOC, strdup, strndup): Likewise.
+	* lib/verify.h: Likewise.
+	* lib/wchar.in.h (_GL_ATTRIBUTE_DEALLOC, wcsdup): Likewise.
+	* lib/xalloc-oversized.h (xalloc_oversized): Likewise.
+	* lib/fenv-private.h (_FPU_GETCW, _FPU_SETCW, _FPU_GETFPSR,
+	_FPU_SETFPSR): When testing __GNUC__, exclude clang. Use different
+	builtins for clang.
+	* lib/hamt.h (GL_HAMT_THREAD_SAFE): When testing __GNUC__, exclude
+	clang. Enable for clang >= 4.
+	* lib/astrxfrm.c: Use _GL_GNUC_PREREQ.
+	* lib/readutmp.c: Likewise.
+	* lib/strftime.c: Likewise.
+	* tests/test-asyncsafe-linked_list-strong.c: Likewise.
+	* tests/test-asyncsafe-linked_list-weak.c: Likewise.
+	* tests/test-c-strtod-mt.c: Likewise.
+	* tests/test-c-strtof-mt.c: Likewise.
+	* tests/test-c-strtold-mt.c: Likewise.
+	* tests/test-gmtime_r-mt.c: Likewise.
+	* tests/test-intprops.c: Likewise.
+	* tests/test-limits-h.c: Likewise.
+	* tests/test-localtime_r-mt.c: Likewise.
+	* tests/test-memrchr.c: Likewise.
+	* tests/test-nl_langinfo-mt.c: Likewise.
+	* tests/test-setlocale_null-mt-all.c: Likewise.
+	* tests/test-setlocale_null-mt-one.c: Likewise.
+	* tests/test-statat.c: Likewise.
+	* tests/test-xvasprintf.c: Likewise.
+
 2024-08-27  Bruno Haible  <br...@clisp.org>
 
 	doc: Update about psignal.
diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h
index 7326bd4773..9806f2b1a0 100644
--- a/lib/_Noreturn.h
+++ b/lib/_Noreturn.h
@@ -34,7 +34,7 @@
 # elif ((!defined __cplusplus || defined __clang__) \
         && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
             || (!defined __STRICT_ANSI__ \
-                && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
+                && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __clang__ \
                     || (defined __apple_build_version__ \
                         ? 6000000 <= __apple_build_version__ \
                         : 3 < __clang_major__ + (5 <= __clang_minor__))))))
diff --git a/lib/aligned-malloc.h b/lib/aligned-malloc.h
index d7142f5a8c..87d1ec1c67 100644
--- a/lib/aligned-malloc.h
+++ b/lib/aligned-malloc.h
@@ -64,7 +64,7 @@ extern "C" {
 #endif
 #if ((ALIGNMENT) <= MALLOC_ALIGNMENT) || HAVE_POSIX_MEMALIGN || HAVE_ALIGNED_ALLOC || HAVE_MEMALIGN
 
-# if defined aligned_free || __GNUC__ >= 11
+# if defined aligned_free || (__GNUC__ >= 11 && !defined __clang__)
    /* The caller wants an inline function, not a macro,
       or we can use GCC's -Wmismatched-dealloc warning.  */
 static inline void
@@ -79,7 +79,7 @@ aligned_free (void *q)
 # if (ALIGNMENT) <= MALLOC_ALIGNMENT
 /* Simply use malloc.  */
 
-#  if defined aligned_malloc || __GNUC__ >= 11
+#  if defined aligned_malloc || (__GNUC__ >= 11 && !defined __clang__)
    /* The caller wants an inline function, not a macro,
       or GCC's -Wmismatched-dealloc warning might be in effect.  */
 static inline
diff --git a/lib/astrxfrm.c b/lib/astrxfrm.c
index eaedff0a83..f25cf7d493 100644
--- a/lib/astrxfrm.c
+++ b/lib/astrxfrm.c
@@ -26,7 +26,7 @@
 
 /* Avoid false GCC warning "function may return address of local variable"
    regarding result and tmpbuf.  */
-#if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4
+#if _GL_GNUC_PREREQ (4, 8)
 # pragma GCC diagnostic ignored "-Wreturn-local-addr"
 #endif
 
diff --git a/lib/base32.h b/lib/base32.h
index eadbeae56c..8c10948c37 100644
--- a/lib/base32.h
+++ b/lib/base32.h
@@ -27,7 +27,7 @@
 #include <idx.h>
 
 /* Pacify GCC in isubase32.  */
-#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) && !defined __clang__
 # pragma GCC diagnostic ignored "-Wtype-limits"
 #endif
 
diff --git a/lib/base64.h b/lib/base64.h
index 7691f6c4ad..562ba97302 100644
--- a/lib/base64.h
+++ b/lib/base64.h
@@ -27,7 +27,7 @@
 #include <idx.h>
 
 /* Pacify GCC in isubase64.  */
-#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) && !defined __clang__
 # pragma GCC diagnostic ignored "-Wtype-limits"
 #endif
 
diff --git a/lib/dfa.c b/lib/dfa.c
index 0ccb167176..a7a969b6ca 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -80,7 +80,7 @@ c_isdigit (char c)
 #ifndef FALLTHROUGH
 # if 201710L < __STDC_VERSION__
 #  define FALLTHROUGH [[__fallthrough__]]
-# elif ((__GNUC__ >= 7) \
+# elif ((__GNUC__ >= 7 && !defined __clang__) \
         || (defined __apple_build_version__ \
             ? __apple_build_version__ >= 12000000 \
             : __clang_major__ >= 10))
diff --git a/lib/dirent.in.h b/lib/dirent.in.h
index cc6767bc8c..7ba8fc64d8 100644
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -78,7 +78,7 @@ typedef struct gl_directory DIR;
    that can be freed by passing them as the Ith argument to the
    function F.  */
 #ifndef _GL_ATTRIBUTE_DEALLOC
-# if __GNUC__ >= 11
+# if __GNUC__ >= 11 && !defined __clang__
 #  define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
 # else
 #  define _GL_ATTRIBUTE_DEALLOC(f, i)
@@ -152,7 +152,7 @@ _GL_FUNCDECL_RPL (opendir, DIR *,
                   _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
 # else
-#  if !@HAVE_OPENDIR@ || __GNUC__ >= 11
+#  if !@HAVE_OPENDIR@ || (__GNUC__ >= 11 && !defined __clang__)
 _GL_FUNCDECL_SYS (opendir, DIR *,
                   (const char *dir_name),
                   _GL_ARG_NONNULL ((1))
@@ -162,7 +162,8 @@ _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name));
 # endif
 _GL_CXXALIASWARN (opendir);
 #else
-# if @GNULIB_CLOSEDIR@ && !GNULIB_defined_DIR && __GNUC__ >= 11 && !defined opendir
+# if @GNULIB_CLOSEDIR@ && !GNULIB_defined_DIR \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined opendir
 /* For -Wmismatched-dealloc: Associate opendir with closedir or
    rpl_closedir.  */
 _GL_FUNCDECL_SYS (opendir, DIR *,
@@ -274,7 +275,8 @@ _GL_FUNCDECL_RPL (fdopendir, DIR *,
                   _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
 # else
-#  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ || __GNUC__ >= 11
+#  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ \
+      || (__GNUC__ >= 11 && !defined __clang__)
 _GL_FUNCDECL_SYS (fdopendir, DIR *,
                   (int fd),
                   _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
@@ -283,7 +285,8 @@ _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
 # endif
 _GL_CXXALIASWARN (fdopendir);
 #else
-# if @GNULIB_CLOSEDIR@ && __GNUC__ >= 11 && !defined fdopendir
+# if @GNULIB_CLOSEDIR@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined fdopendir
 /* For -Wmismatched-dealloc: Associate fdopendir with closedir or
    rpl_closedir.  */
 _GL_FUNCDECL_SYS (fdopendir, DIR *,
diff --git a/lib/fenv-private.h b/lib/fenv-private.h
index e92c9de228..9571b7b93d 100644
--- a/lib/fenv-private.h
+++ b/lib/fenv-private.h
@@ -133,9 +133,12 @@ x86_387_fenv_t;
    occurring, trigger a trap rather than merely set the corresponding bit
    in the fpsr register.  */
 
-# if __GNUC__ >= 6
+# if __GNUC__ >= 6 && !defined __clang__
 #  define _FPU_GETCW(fpcr) (fpcr = __builtin_aarch64_get_fpcr ())
 #  define _FPU_SETCW(fpcr) __builtin_aarch64_set_fpcr (fpcr)
+# elif __clang_major__ >= 4
+#  define _FPU_GETCW(fpcr) (fpcr = __builtin_arm_rsr ("fpcr"))
+#  define _FPU_SETCW(fpcr) __builtin_arm_wsr ("fpcr", fpcr)
 # else
 #  define _FPU_GETCW(fpcr) \
    __asm__ __volatile__ ("mrs %0, fpcr" : "=r" (fpcr))
@@ -143,9 +146,12 @@ x86_387_fenv_t;
    __asm__ __volatile__ ("msr fpcr, %0" : : "r" (fpcr))
 # endif
 
-# if __GNUC__ >= 6
+# if __GNUC__ >= 6 && !defined __clang__
 #  define _FPU_GETFPSR(fpsr) (fpsr = __builtin_aarch64_get_fpsr ())
 #  define _FPU_SETFPSR(fpsr) __builtin_aarch64_set_fpsr (fpsr)
+# elif __clang_major__ >= 4
+#  define _FPU_GETFPSR(fpsr) (fpsr = __builtin_arm_rsr ("fpsr"))
+#  define _FPU_SETFPSR(fpsr) __builtin_arm_wsr ("fpsr", fpsr)
 # else
 #  define _FPU_GETFPSR(fpsr) \
    __asm__ __volatile__ ("mrs %0, fpsr" : "=r" (fpsr))
diff --git a/lib/hamt.h b/lib/hamt.h
index a25c612731..b483aa1bbe 100644
--- a/lib/hamt.h
+++ b/lib/hamt.h
@@ -61,9 +61,10 @@ _GL_INLINE_HEADER_BEGIN
    the same hamt.  This is non-trivial as different hamts may share
    some structure.
    We can define it only when the compiler supports _Atomic.  For GCC,
-   it is supported starting with GCC 4.9.  */
+   it is supported starting with GCC 4.9.  For clang, with clang 4.  */
 
-#if (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) \
+#if (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __clang \
+     || __clang_major__ >= 4) \
     && __STDC_VERSION__ >= 201112L && !defined __STD_NO_ATOMICS__ \
     && !defined __cplusplus
 # define GL_HAMT_THREAD_SAFE 1
diff --git a/lib/intprops-internal.h b/lib/intprops-internal.h
index 443024c665..c8cc0e2019 100644
--- a/lib/intprops-internal.h
+++ b/lib/intprops-internal.h
@@ -21,7 +21,7 @@
 #include <limits.h>
 
 /* Pacify GCC 13.2 in some calls to _GL_EXPR_SIGNED.  */
-#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) && !defined __clang__
 # pragma GCC diagnostic ignored "-Wtype-limits"
 #endif
 
@@ -163,7 +163,7 @@
 #if _GL_HAS_BUILTIN_MUL_OVERFLOW
 # if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
        || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \
-      && !defined __EDG__)
+      && !defined __clang__ && !defined __EDG__)
 #  define _GL_INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r)
 # else
    /* Work around GCC bug 91450.  */
diff --git a/lib/jit/cache.h b/lib/jit/cache.h
index 94aef30526..16835d5e00 100644
--- a/lib/jit/cache.h
+++ b/lib/jit/cache.h
@@ -167,7 +167,7 @@ clear_cache (void *start, void *end)
     : "d" (addr), "d" (len)
     : "%d0", "%d2", "%d3"
     );
-#elif (__GNUC__ + (__GNUC_MINOR__ >= 3) > 4) \
+#elif (__GNUC__ + (__GNUC_MINOR__ >= 3) > 4 && !defined __clang__) \
       || ((__clang_major__ + (__clang_minor__ >= 4) > 3) \
           && (defined __aarch64__ /* arm64 */ || defined __arm__))
   /* GCC >= 4.3 has a GCC built-in.
diff --git a/lib/malloc.in.h b/lib/malloc.in.h
index 19e82f284f..a22a4a8a39 100644
--- a/lib/malloc.in.h
+++ b/lib/malloc.in.h
@@ -148,7 +148,7 @@ _GL_FUNCDECL_RPL (memalign, void *,
 _GL_CXXALIAS_RPL (memalign, void *, (size_t alignment, size_t size));
 # else
 #  if @HAVE_MEMALIGN@
-#   if __GNUC__ >= 11
+#   if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate memalign with free or rpl_free.  */
 #    if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (memalign, void *,
@@ -170,7 +170,7 @@ _GL_CXXALIAS_SYS (memalign, void *, (size_t alignment, size_t size));
 _GL_CXXALIASWARN (memalign);
 # endif
 #else
-# if __GNUC__ >= 11 && !defined memalign
+# if (__GNUC__ >= 11 && !defined __clang__) && !defined memalign
 /* For -Wmismatched-dealloc: Associate memalign with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (memalign, void *,
diff --git a/lib/mcel.h b/lib/mcel.h
index d9f8385155..e5b0765bff 100644
--- a/lib/mcel.h
+++ b/lib/mcel.h
@@ -109,7 +109,7 @@ extern "C" {
 
 
 /* Pacify GCC re type limits.  */
-#if defined __GNUC__ && 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) && !defined __clang__
 # pragma GCC diagnostic ignored "-Wtype-limits"
 #endif
 
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 3c4f97b146..0938a094cb 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -148,7 +148,7 @@
 /* Size of the ut->ut_host member.  */
 #define UT_HOST_SIZE  sizeof (((struct UTMP_STRUCT_NAME *) 0)->ut_host)
 
-#if 8 <= __GNUC__
+#if _GL_GNUC_PREREQ (8, 0)
 # pragma GCC diagnostic ignored "-Wsizeof-pointer-memaccess"
 #endif
 
diff --git a/lib/regex.h b/lib/regex.h
index ccf40cebc0..71a45f8c27 100644
--- a/lib/regex.h
+++ b/lib/regex.h
@@ -531,7 +531,8 @@ typedef struct
 # endif
 #endif
 
-#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+#if (defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
+     && !defined __clang__)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wvla"
 #endif
@@ -539,7 +540,7 @@ typedef struct
 #ifndef _Attr_access_
 # ifdef __attr_access
 #  define _Attr_access_(arg) __attr_access (arg)
-# elif defined __GNUC__ && 10 <= __GNUC__
+# elif defined __GNUC__ && 10 <= __GNUC__ && !defined __clang__
 #  define _Attr_access_(x) __attribute__ ((__access__ x))
 # else
 #  define _Attr_access_(x)
@@ -688,7 +689,8 @@ extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
 
 extern void regfree (regex_t *__preg);
 
-#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+#if (defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
+     && !defined __clang__)
 # pragma GCC diagnostic pop
 #endif
 
diff --git a/lib/stddef.in.h b/lib/stddef.in.h
index 49449315cf..e39268c60c 100644
--- a/lib/stddef.in.h
+++ b/lib/stddef.in.h
@@ -194,7 +194,7 @@ typedef union
 # ifndef _GL_HAS_BUILTIN_UNREACHABLE
 #  if defined __clang_major__ && __clang_major__ < 5
 #   define _GL_HAS_BUILTIN_UNREACHABLE 0
-#  elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
+#  elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) && !defined __clang__
 #   define _GL_HAS_BUILTIN_UNREACHABLE 1
 #  elif defined __has_builtin
 #   define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 9ace64b5be..ace2a21352 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -120,7 +120,7 @@
    that can be freed by passing them as the Ith argument to the
    function F.  */
 #ifndef _GL_ATTRIBUTE_DEALLOC
-# if __GNUC__ >= 11
+# if __GNUC__ >= 11 && !defined __clang__
 #  define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
 # else
 #  define _GL_ATTRIBUTE_DEALLOC(f, i)
@@ -392,7 +392,7 @@ _GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
 #  endif
 _GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode));
 # else
-#  if __GNUC__ >= 11
+#  if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose.  */
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (fdopen, FILE *,
@@ -413,7 +413,7 @@ _GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
 # endif
 _GL_CXXALIASWARN (fdopen);
 #else
-# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fdopen
+# if @GNULIB_FCLOSE@ && (__GNUC__ >= 11 && !defined __clang__) && !defined fdopen
 /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (fdopen, FILE *,
@@ -542,7 +542,7 @@ _GL_FUNCDECL_RPL (fopen, FILE *,
 _GL_CXXALIAS_RPL (fopen, FILE *,
                   (const char *restrict filename, const char *restrict mode));
 # else
-#  if __GNUC__ >= 11
+#  if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose.  */
 _GL_FUNCDECL_SYS (fopen, FILE *,
                   (const char *restrict filename, const char *restrict mode),
@@ -556,7 +556,7 @@ _GL_CXXALIAS_SYS (fopen, FILE *,
 _GL_CXXALIASWARN (fopen);
 # endif
 #else
-# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fopen
+# if @GNULIB_FCLOSE@ && (__GNUC__ >= 11 && !defined __clang__) && !defined fopen
 /* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose.  */
 _GL_FUNCDECL_SYS (fopen, FILE *,
                   (const char *restrict filename, const char *restrict mode),
@@ -1248,7 +1248,7 @@ _GL_FUNCDECL_RPL (popen, FILE *,
                   _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
 # else
-#  if !@HAVE_POPEN@ || __GNUC__ >= 11
+#  if !@HAVE_POPEN@ || (__GNUC__ >= 11 && !defined __clang__)
 _GL_FUNCDECL_SYS (popen, FILE *,
                   (const char *cmd, const char *mode),
                   _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)
@@ -1258,7 +1258,8 @@ _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
 # endif
 _GL_CXXALIASWARN (popen);
 #else
-# if @GNULIB_PCLOSE@ && __GNUC__ >= 11 && !defined popen
+# if @GNULIB_PCLOSE@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined popen
 /* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose.  */
 _GL_FUNCDECL_SYS (popen, FILE *,
                   (const char *cmd, const char *mode),
@@ -1667,7 +1668,7 @@ _GL_FUNCDECL_RPL (tmpfile, FILE *, (void),
                                    _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
 # else
-#  if __GNUC__ >= 11
+#  if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose.  */
 _GL_FUNCDECL_SYS (tmpfile, FILE *, (void),
                                    _GL_ATTRIBUTE_DEALLOC (fclose, 1)
@@ -1680,7 +1681,8 @@ _GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
 _GL_CXXALIASWARN (tmpfile);
 # endif
 #else
-# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile
+# if @GNULIB_FCLOSE@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined tmpfile
 /* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose.  */
 _GL_FUNCDECL_SYS (tmpfile, FILE *, (void),
                                    _GL_ATTRIBUTE_DEALLOC (fclose, 1)
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 2a94b73f72..1ec96c8b24 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -132,7 +132,7 @@ struct random_data
    that can be freed by passing them as the Ith argument to the
    function F.  */
 #ifndef _GL_ATTRIBUTE_DEALLOC
-# if __GNUC__ >= 11
+# if __GNUC__ >= 11 && !defined __clang__
 #  define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
 # else
 #  define _GL_ATTRIBUTE_DEALLOC(f, i)
@@ -300,7 +300,7 @@ _GL_FUNCDECL_RPL (aligned_alloc, void *,
 _GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
 # else
 #  if @HAVE_ALIGNED_ALLOC@
-#   if __GNUC__ >= 11
+#   if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free.  */
 #    if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
 _GL_FUNCDECL_SYS (aligned_alloc, void *,
@@ -322,7 +322,8 @@ _GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size));
 _GL_CXXALIASWARN (aligned_alloc);
 # endif
 #else
-# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined aligned_alloc
+# if @GNULIB_FREE_POSIX@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined aligned_alloc
 /* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
 _GL_FUNCDECL_SYS (aligned_alloc, void *,
@@ -376,7 +377,7 @@ _GL_FUNCDECL_RPL (calloc, void *,
                   _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size));
 # else
-#  if __GNUC__ >= 11
+#  if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate calloc with free or rpl_free.  */
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (calloc, void *,
@@ -397,7 +398,8 @@ _GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size));
 _GL_CXXALIASWARN (calloc);
 # endif
 #else
-# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined calloc
+# if @GNULIB_FREE_POSIX@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined calloc
 /* For -Wmismatched-dealloc: Associate calloc with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (calloc, void *,
@@ -430,7 +432,7 @@ _GL_FUNCDECL_RPL (canonicalize_file_name, char *,
                   _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name));
 # else
-#  if !@HAVE_CANONICALIZE_FILE_NAME@ || __GNUC__ >= 11
+#  if !@HAVE_CANONICALIZE_FILE_NAME@ || (__GNUC__ >= 11 && !defined __clang__)
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (canonicalize_file_name, char *,
                   (const char *name),
@@ -454,7 +456,8 @@ _GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name));
 # endif
 _GL_CXXALIASWARN (canonicalize_file_name);
 #else
-# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined canonicalize_file_name
+# if @GNULIB_FREE_POSIX@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined canonicalize_file_name
 /* For -Wmismatched-dealloc: Associate canonicalize_file_name with free or
    rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
@@ -689,7 +692,7 @@ _GL_FUNCDECL_RPL (malloc, void *,
                   _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (malloc, void *, (size_t size));
 # else
-#  if __GNUC__ >= 11
+#  if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate malloc with free or rpl_free.  */
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (malloc, void *,
@@ -710,7 +713,8 @@ _GL_CXXALIAS_SYS (malloc, void *, (size_t size));
 _GL_CXXALIASWARN (malloc);
 # endif
 #else
-# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined malloc
+# if @GNULIB_FREE_POSIX@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined malloc
 /* For -Wmismatched-dealloc: Associate malloc with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (malloc, void *,
@@ -1460,7 +1464,7 @@ _GL_FUNCDECL_RPL (realloc, void *,
                   _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
 # else
-#  if __GNUC__ >= 11
+#  if __GNUC__ >= 11 && !defined __clang__
 /* For -Wmismatched-dealloc: Associate realloc with free or rpl_free.  */
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (realloc, void *,
@@ -1479,7 +1483,8 @@ _GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
 _GL_CXXALIASWARN (realloc);
 # endif
 #else
-# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined realloc
+# if @GNULIB_FREE_POSIX@ \
+     && (__GNUC__ >= 11 && !defined __clang__) && !defined realloc
 /* For -Wmismatched-dealloc: Associate realloc with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
 _GL_FUNCDECL_SYS (realloc, void *,
diff --git a/lib/strftime.c b/lib/strftime.c
index 9b1b27a1fc..4ddbec0426 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -321,7 +321,7 @@ enum pad_style
    maximum object size 9223372036854775807", caused by insufficient data flow
    analysis and value propagation of the 'width_add' expansion when GCC is not
    optimizing.  Cf. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443>.  */
-#if __GNUC__ >= 7 && !__OPTIMIZE__
+#if _GL_GNUC_PREREQ (7, 0) && !__OPTIMIZE__
 # pragma GCC diagnostic ignored "-Wstringop-overflow"
 #endif
 
diff --git a/lib/string.in.h b/lib/string.in.h
index b415982d3c..a588e7e2c2 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -79,7 +79,7 @@
    that can be freed by passing them as the Ith argument to the
    function F.  */
 #ifndef _GL_ATTRIBUTE_DEALLOC
-# if __GNUC__ >= 11
+# if __GNUC__ >= 11 && !defined __clang__
 #  define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
 # else
 #  define _GL_ATTRIBUTE_DEALLOC(f, i)
@@ -621,7 +621,8 @@ _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
     /* strdup exists as a function and as a macro.  Get rid of the macro.  */
 #   undef strdup
 #  endif
-#  if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
+#  if (!@HAVE_DECL_STRDUP@ || (__GNUC__ >= 11 && !defined __clang__)) \
+      && !defined strdup
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (strdup, char *,
                   (char const *__s),
@@ -639,7 +640,7 @@ _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
 # endif
 _GL_CXXALIASWARN (strdup);
 #else
-# if __GNUC__ >= 11 && !defined strdup
+# if (__GNUC__ >= 11 && !defined __clang__) && !defined strdup
 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (strdup, char *,
@@ -720,7 +721,8 @@ _GL_FUNCDECL_RPL (strndup, char *,
                   _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
 _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
 # else
-#  if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup)
+#  if !@HAVE_DECL_STRNDUP@ \
+      || ((__GNUC__ >= 11 && !defined __clang__) && !defined strndup)
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (strndup, char *,
                   (char const *__s, size_t __n),
@@ -738,7 +740,7 @@ _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
 # endif
 _GL_CXXALIASWARN (strndup);
 #else
-# if __GNUC__ >= 11 && !defined strndup
+# if (__GNUC__ >= 11 && !defined __clang__) && !defined strndup
 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (strndup, char *,
diff --git a/lib/verify.h b/lib/verify.h
index 978926a491..49a73c0508 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -34,11 +34,12 @@
 #ifndef __cplusplus
 # if (201112 <= __STDC_VERSION__ \
       || (!defined __STRICT_ANSI__ \
-          && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 5 <= __clang_major__)))
+          && ((4 < __GNUC__ + (6 <= __GNUC_MINOR__) && !defined __clang__) \
+              || 5 <= __clang_major__)))
 #  define _GL_HAVE__STATIC_ASSERT 1
 # endif
 # if (202311 <= __STDC_VERSION__ \
-      || (!defined __STRICT_ANSI__ && 9 <= __GNUC__))
+      || (!defined __STRICT_ANSI__ && 9 <= __GNUC__ && !defined __clang__))
 #  define _GL_HAVE__STATIC_ASSERT1 1
 # endif
 #endif
@@ -215,7 +216,7 @@ template <int w>
 # define _GL_VERIFY(R, DIAGNOSTIC, ...) \
     extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
       [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
-# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) && !defined __clang__
 #  pragma GCC diagnostic ignored "-Wnested-externs"
 # endif
 #endif
@@ -305,7 +306,7 @@ template <int w>
 #ifndef _GL_HAS_BUILTIN_UNREACHABLE
 # if defined __clang_major__ && __clang_major__ < 5
 #  define _GL_HAS_BUILTIN_UNREACHABLE 0
-# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
+# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) && !defined __clang__
 #  define _GL_HAS_BUILTIN_UNREACHABLE 1
 # elif defined __has_builtin
 #  define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index 785e74787e..ac7cb00fc7 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -95,7 +95,7 @@
    that can be freed by passing them as the Ith argument to the
    function F.  */
 #ifndef _GL_ATTRIBUTE_DEALLOC
-# if __GNUC__ >= 11
+# if __GNUC__ >= 11 && !defined __clang__
 #  define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
 # else
 #  define _GL_ATTRIBUTE_DEALLOC(f, i)
@@ -1326,7 +1326,8 @@ _GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s));
 /* On Solaris 11.3, the header files declare the function in the std::
    namespace, not in the global namespace.  So, force a declaration in
    the global namespace.  */
-#  if !@HAVE_WCSDUP@ || (defined __sun && defined __cplusplus) || __GNUC__ >= 11
+#  if !@HAVE_WCSDUP@ || (defined __sun && defined __cplusplus) \
+      || (__GNUC__ >= 11 && !defined __clang__)
 #   if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (wcsdup, wchar_t *,
                   (const wchar_t *s),
@@ -1342,7 +1343,7 @@ _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
 # endif
 _GL_CXXALIASWARN (wcsdup);
 #else
-# if __GNUC__ >= 11 && !defined wcsdup
+# if (__GNUC__ >= 11 && !defined __clang__) && !defined wcsdup
 /* For -Wmismatched-dealloc: Associate wcsdup with free or rpl_free.  */
 #  if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
 _GL_FUNCDECL_SYS (wcsdup, wchar_t *,
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h
index 7f30f83e76..cfa527d38c 100644
--- a/lib/xalloc-oversized.h
+++ b/lib/xalloc-oversized.h
@@ -47,7 +47,8 @@
 #if 7 <= __GNUC__ && !defined __clang__ && PTRDIFF_MAX < SIZE_MAX
 # define xalloc_oversized(n, s) \
    __builtin_mul_overflow_p (n, s, (ptrdiff_t) 1)
-#elif 5 <= __GNUC__ && !defined __ICC && PTRDIFF_MAX < SIZE_MAX
+#elif 5 <= __GNUC__ && !defined __clang__ && !defined __ICC \
+      && PTRDIFF_MAX < SIZE_MAX
 # define xalloc_oversized(n, s) \
    (__builtin_constant_p (n) && __builtin_constant_p (s) \
     ? __xalloc_oversized (n, s) \
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 0f0eb07c44..d985522893 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,5 +1,5 @@
 # gnulib-common.m4
-# serial 102
+# serial 103
 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -1355,7 +1355,7 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS]
     dnl -Wno-unused-parameter                 >= 3            >= 3.9
     dnl
     cat > conftest.c <<\EOF
-      #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      #if (__GNUC__ >= 3 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wno-cast-qual
       -Wno-conversion
       -Wno-float-equal
@@ -1364,23 +1364,23 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS]
       -Wno-unused-function
       -Wno-unused-parameter
       #endif
-      #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      #if (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wno-float-conversion
       #endif
-      #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      #if (__GNUC__ >= 7 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wimplicit-fallthrough
       #endif
-      #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      #if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wno-pedantic
       #endif
       #if 3 < __clang_major__ + (9 <= __clang_minor__)
       -Wno-tautological-constant-out-of-range-compare
       #endif
-      #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      #if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
       -Wno-sign-conversion
       -Wno-type-limits
       #endif
-      #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
+      #if (__GNUC__ + (__GNUC_MINOR__ >= 5) > 4 && !defined __clang__)
       -Wno-unsuffixed-float-constants
       #endif
 EOF
diff --git a/tests/test-asyncsafe-linked_list-strong.c b/tests/test-asyncsafe-linked_list-strong.c
index d90f08288f..67ba4f0b4e 100644
--- a/tests/test-asyncsafe-linked_list-strong.c
+++ b/tests/test-asyncsafe-linked_list-strong.c
@@ -44,7 +44,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-asyncsafe-linked_list-weak.c b/tests/test-asyncsafe-linked_list-weak.c
index fa2e908707..4d9bcad58a 100644
--- a/tests/test-asyncsafe-linked_list-weak.c
+++ b/tests/test-asyncsafe-linked_list-weak.c
@@ -44,7 +44,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-c-strtod-mt.c b/tests/test-c-strtod-mt.c
index f900014a20..a21cd37993 100644
--- a/tests/test-c-strtod-mt.c
+++ b/tests/test-c-strtod-mt.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-c-strtof-mt.c b/tests/test-c-strtof-mt.c
index fc797f9a52..5f18c917d2 100644
--- a/tests/test-c-strtof-mt.c
+++ b/tests/test-c-strtof-mt.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-c-strtold-mt.c b/tests/test-c-strtold-mt.c
index 0b48eb8bfc..6468b470f4 100644
--- a/tests/test-c-strtold-mt.c
+++ b/tests/test-c-strtold-mt.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-gmtime_r-mt.c b/tests/test-gmtime_r-mt.c
index 95a36ac682..87a5e7cc59 100644
--- a/tests/test-gmtime_r-mt.c
+++ b/tests/test-gmtime_r-mt.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-intprops.c b/tests/test-intprops.c
index 8d3b8c37e6..3bffc3f5a4 100644
--- a/tests/test-intprops.c
+++ b/tests/test-intprops.c
@@ -16,9 +16,12 @@
 
 /* Written by Paul Eggert.  */
 
+#include <config.h>
+
+#if _GL_GNUC_PREREQ (4, 3)
+
 /* Tell gcc not to warn about the long expressions that the overflow
    macros expand to, or about the (X < 0) expressions.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
 # pragma GCC diagnostic ignored "-Woverlength-strings"
 # pragma GCC diagnostic ignored "-Wtype-limits"
 
@@ -28,8 +31,6 @@
 
 #endif
 
-#include <config.h>
-
 #ifdef TEST_STDCKDINT
 # include <stdckdint.h>
 #else
diff --git a/tests/test-limits-h.c b/tests/test-limits-h.c
index 6f574c88a0..885fe1f017 100644
--- a/tests/test-limits-h.c
+++ b/tests/test-limits-h.c
@@ -20,7 +20,7 @@
 
 #include <limits.h>
 
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Woverlength-strings"
 #endif
 
diff --git a/tests/test-localtime_r-mt.c b/tests/test-localtime_r-mt.c
index 096c83eb70..d7baeff414 100644
--- a/tests/test-localtime_r-mt.c
+++ b/tests/test-localtime_r-mt.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-memrchr.c b/tests/test-memrchr.c
index a6f15ceff7..836ed6f25d 100644
--- a/tests/test-memrchr.c
+++ b/tests/test-memrchr.c
@@ -28,7 +28,7 @@ SIGNATURE_CHECK (memrchr, void *, (void const *, int, size_t));
 #include "macros.h"
 
 /* Work around GCC bug 101494.  */
-#if 4 < __GNUC__ + (7 <= __GNUC_MINOR__) && __GNUC__ < 12
+#if _GL_GNUC_PREREQ (4, 7) && __GNUC__ < 12
 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #endif
 
diff --git a/tests/test-nl_langinfo-mt.c b/tests/test-nl_langinfo-mt.c
index b7e16fccce..2325ee91d6 100644
--- a/tests/test-nl_langinfo-mt.c
+++ b/tests/test-nl_langinfo-mt.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-setlocale_null-mt-all.c b/tests/test-setlocale_null-mt-all.c
index d565aa0382..567a289fa9 100644
--- a/tests/test-setlocale_null-mt-all.c
+++ b/tests/test-setlocale_null-mt-all.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-setlocale_null-mt-one.c b/tests/test-setlocale_null-mt-one.c
index cbd057f94f..cc504812d6 100644
--- a/tests/test-setlocale_null-mt-one.c
+++ b/tests/test-setlocale_null-mt-one.c
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Work around GCC bug 44511.  */
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wreturn-type"
 #endif
 
diff --git a/tests/test-statat.c b/tests/test-statat.c
index a093caeeb3..0576f8f204 100644
--- a/tests/test-statat.c
+++ b/tests/test-statat.c
@@ -18,7 +18,7 @@
 
 #include "openat.h"
 
-#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 #endif
 
diff --git a/tests/test-xvasprintf.c b/tests/test-xvasprintf.c
index 038b0c242b..32b82cbb72 100644
--- a/tests/test-xvasprintf.c
+++ b/tests/test-xvasprintf.c
@@ -16,15 +16,15 @@
 
 /* Written by Bruno Haible <br...@clisp.org>, 2007.  */
 
+#include <config.h>
+
 /* Tell GCC not to warn about the specific edge cases tested here.  */
-#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+#if _GL_GNUC_PREREQ (4, 3)
 # pragma GCC diagnostic ignored "-Wformat-zero-length"
 # pragma GCC diagnostic ignored "-Wformat-nonliteral"
 # pragma GCC diagnostic ignored "-Wformat-security"
 #endif
 
-#include <config.h>
-
 #include "xvasprintf.h"
 
 #include <stdarg.h>
-- 
2.34.1

>From 348857d076c99afc532d9f4dbf0c24bbd41a7b36 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 27 Aug 2024 21:40:15 +0200
Subject: [PATCH 2/2] Improve support for clang on Windows.

* lib/c++defs.h (_GL_CXXALIASWARN_2): Treat clang like gcc 4.2.
* lib/stdio.in.h (fwrite, fwrite_unlocked): Likewise.
* lib/warn-on-use.h (_GL_WARN_ON_USE, _GL_WARN_ON_USE_CXX): Likewise.
* lib/libc-config.h (__GNUC_PREREQ): Override glibc's definition to
handle clang in disguise.
---
 ChangeLog         | 9 +++++++++
 lib/c++defs.h     | 2 +-
 lib/libc-config.h | 5 +++++
 lib/stdio.in.h    | 4 ++--
 lib/warn-on-use.h | 4 ++--
 5 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e372f307cf..43c89e2a92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-08-27  Bruno Haible  <br...@clisp.org>
+
+	Improve support for clang on Windows.
+	* lib/c++defs.h (_GL_CXXALIASWARN_2): Treat clang like gcc 4.2.
+	* lib/stdio.in.h (fwrite, fwrite_unlocked): Likewise.
+	* lib/warn-on-use.h (_GL_WARN_ON_USE, _GL_WARN_ON_USE_CXX): Likewise.
+	* lib/libc-config.h (__GNUC_PREREQ): Override glibc's definition to
+	handle clang in disguise.
+
 2024-08-27  Bruno Haible  <br...@clisp.org>
 
 	Explicitly exclude clang when we test for a GCC version >= 4.3.
diff --git a/lib/c++defs.h b/lib/c++defs.h
index af5e9bb2b3..7082af3fc2 100644
--- a/lib/c++defs.h
+++ b/lib/c++defs.h
@@ -314,7 +314,7 @@
     _GL_WARN_ON_USE (func, \
                      "The symbol ::" #func " refers to the system function. " \
                      "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
 #  define _GL_CXXALIASWARN_2(func,namespace) \
      extern __typeof__ (func) func
 # else
diff --git a/lib/libc-config.h b/lib/libc-config.h
index 70114608fb..33bdb73660 100644
--- a/lib/libc-config.h
+++ b/lib/libc-config.h
@@ -48,6 +48,11 @@
 
 /* From glibc <features.h>.  */
 
+#if defined __clang__
+  /* clang really only groks GNU C 4.2, regardless of its value of __GNUC__.  */
+# undef __GNUC_PREREQ
+# define __GNUC_PREREQ(maj, min) ((maj) < 4 + ((min) <= 2))
+#endif
 #ifndef __GNUC_PREREQ
 # if defined __GNUC__ && defined __GNUC_MINOR__
 #  define __GNUC_PREREQ(maj, min) ((maj) < __GNUC__ + ((min) <= __GNUC_MINOR__))
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index ace2a21352..36fd6a72ce 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -949,9 +949,9 @@ _GL_CXXALIAS_SYS (fwrite, size_t,
    which sometimes causes an unwanted diagnostic for fwrite calls.
    This affects only function declaration attributes under certain
    versions of gcc and clang, and is not needed for C++.  */
-#  if (0 < __USE_FORTIFY_LEVEL                                          \
+#  if (0 < __USE_FORTIFY_LEVEL                                            \
        && __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \
-       && 3 < __GNUC__ + (4 <= __GNUC_MINOR__)                          \
+       && (3 < __GNUC__ + (4 <= __GNUC_MINOR__) || defined __clang__)     \
        && !defined __cplusplus)
 #   undef fwrite
 #   undef fwrite_unlocked
diff --git a/lib/warn-on-use.h b/lib/warn-on-use.h
index e3b1fefe50..73c439714a 100644
--- a/lib/warn-on-use.h
+++ b/lib/warn-on-use.h
@@ -98,7 +98,7 @@ _GL_WARN_EXTERN_C __typeof__ (function) function \
   __attribute__ ((__diagnose_if__ (1, message, "warning")))
 #  define _GL_WARN_ON_USE_ATTRIBUTE(message) \
   __attribute__ ((__diagnose_if__ (1, message, "warning")))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
 /* Verify the existence of the function.  */
 #  define _GL_WARN_ON_USE(function, message) \
 _GL_WARN_EXTERN_C __typeof__ (function) function
@@ -131,7 +131,7 @@ extern rettype_gcc function parameters_and_attributes \
 #   define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
 extern rettype_clang function parameters_and_attributes \
   __attribute__ ((__diagnose_if__ (1, msg, "warning")))
-#  elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+#  elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
 /* Verify the existence of the function.  */
 #   define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
 extern rettype_gcc function parameters_and_attributes
-- 
2.34.1

Reply via email to