On 08/05/2026 14:08, Bruno Haible wrote:
Pádraig Brady wrote:
As of gnulib commit 4a127339b244
coreutils CI is failing on GCC 10 with:

CC       src/coreutils-coreutils.o
cc1: error: command-line option '-Wuseless-cast' is valid for C++/ObjC++ but 
not for C [-Werror]
cc1: all warnings being treated as errors

I can reproduce it by configuring coreutils with
   ./configure --enable-gcc-warnings
with gcc 13.

The config.log contains this:

configure:97102: checking whether C compiler handles -Wuseless-cast
configure:97122: gcc -o conftest -g -O2  -Wuseless-cast   conftest.c  >&5
cc1: warning: command-line option '-Wuseless-cast' is valid for C++/ObjC++ but 
not for C
configure:97122: $? = 0
configure:97136: result: yes

It looks like manywarnings.m4 should only try this option if the gcc version
is >= 14.
Ah right.

Since GCC 14 was only released 2 years ago,
I've pushed the attached to avoid this issue on older compilers.

I verified it avoids the issue on GCC 10.

thanks!
Padraig
From b933a2ef8648bdac1f60fbc3cfbf285858344a93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Fri, 8 May 2026 15:17:53 +0100
Subject: [PATCH] manywarnings: avoid -Wuseless-cast warnings on GCC <= 13

* m4/manywarnings.m4: Only consider -Wuseless-cast on GCC >= 14
Fix suggested by Bruno Haible.
---
 ChangeLog          |  6 ++++++
 m4/manywarnings.m4 | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d1a36a44ab..cf9294505c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-05-08  Pádraig Brady  <[email protected]>
+
+	manywarnings: avoid -Wuseless-cast warnings on GCC <= 13
+	* m4/manywarnings.m4: Only consider -Wuseless-cast on GCC >= 14
+	Fix suggested by Bruno Haible.
+
 2026-05-08  Bruno Haible  <[email protected]>
 
 	Revisit some -Wuseless-cast changes.
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index fe382e93e4..6e08abd68f 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,5 +1,5 @@
 # manywarnings.m4
-# serial 34
+# serial 35
 dnl Copyright (C) 2008-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -147,7 +147,6 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
     -Wunknown-pragmas \
     -Wunsafe-loop-optimizations \
     -Wunused-macros \
-    -Wuseless-cast \
     -Wvariadic-macros \
     -Wvector-operation-performance \
     -Wvla \
@@ -184,6 +183,15 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
         AS_VAR_APPEND([$1], [' -fno-common'])
           ;;
     esac
+    case $gl_gcc_version in
+      gcc*' ('*') '?.* | gcc*' ('*') '1[[0-3]].*)
+          # In GCC < 14 the option either does not exist,
+          # or is accepted but always warns.
+          ;;
+      *)
+          AS_VAR_APPEND([$1], [' -Wuseless-cast'])
+          ;;
+    esac
     case $gl_gcc_version in
       gcc*' ('*') '?.* | gcc*' ('*') '1[[0-4]].*)
           # In GCC < 15 the option either does not exist,
-- 
2.54.0

Reply via email to