Compiling the newest coreutils from git, in a git checkout with no '.tarball-version' file, with gcc 14 produces the following errors:
gcc-14 -ftrapv -I. -I./lib -Ilib -I./lib -Isrc -I./src -Werror -fstrict-flex-arrays -Wall -Warith-conversion -Wbad-function-cast -Wcast-align=strict -Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra -Wformat-signedness -Wflex-array-member-not-at-end -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnull-dereference -Wopenmp-simd -Woverlength-strings -Wpacked -Wpointer-arith -Wshadow -Wstrict-flex-arrays -Wstrict-prototypes -Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wtrampolines -Wunknown-pragmas -Wvariadic-macros -Wvla -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wbidi-chars=any,ucn -Wformat=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 -Wuse-after-free=3 -Wunused-const-variable=2 -Wvla-larger-than=4031 -Wswitch-enum -Wno-sign-compare -Wno-unused-parameter -Wno-format-nonliteral -fdiagnostics-show-option -funit-at-a-time -Wno-return-local-addr -Wno-stringop-overflow -Wno-cast-qual -Wno-conversion -Wno-float-equal -Wno-sign-compare -Wno-undef -Wno-unused-function -Wno-unused-parameter -Wno-float-conversion -Wimplicit-fallthrough -Wno-pedantic -Wno-sign-conversion -Wno-type-limits -Wno-unused-const-variable -Wno-unsuffixed-float-constants -g -O2 -MT lib/libcoreutils_a-readutmp.o -MD -MP -MF lib/.deps/libcoreutils_a-readutmp.Tpo -c -o lib/libcoreutils_a-readutmp.o `test -f 'lib/readutmp.c' || echo './'`lib/readutmp.c lib/readutmp.c: In function 'have_boot_time': lib/readutmp.c:305:1: error: function might be candidate for attribute 'pure' if it is known to return normally [-Werror=suggest-attribute=pure] 305 | have_boot_time (struct utmp_alloc a) | ^~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:17464: lib/libcoreutils_a-readutmp.o] Error 1 gcc-14 -ftrapv -I. -I./lib -Ilib -I./lib -Isrc -I./src -Werror -fstrict-flex-arrays -Wall -Warith-conversion -Wbad-function-cast -Wcast-align=strict -Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra -Wformat-signedness -Wflex-array-member-not-at-end -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnull-dereference -Wopenmp-simd -Woverlength-strings -Wpacked -Wpointer-arith -Wshadow -Wstrict-flex-arrays -Wstrict-prototypes -Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wtrampolines -Wunknown-pragmas -Wvariadic-macros -Wvla -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wbidi-chars=any,ucn -Wformat=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 -Wuse-after-free=3 -Wunused-const-variable=2 -Wvla-larger-than=4031 -Wswitch-enum -Wno-sign-compare -Wno-unused-parameter -Wno-format-nonliteral -fdiagnostics-show-option -funit-at-a-time -Wno-return-local-addr -Wno-stringop-overflow -Wno-cast-qual -Wno-conversion -Wno-float-equal -Wno-sign-compare -Wno-undef -Wno-unused-function -Wno-unused-parameter -Wno-float-conversion -Wimplicit-fallthrough -Wno-pedantic -Wno-sign-conversion -Wno-type-limits -Wno-unused-const-variable -Wno-unsuffixed-float-constants -g -O2 -MT lib/libcoreutils_a-printf-args.o -MD -MP -MF lib/.deps/libcoreutils_a-printf-args.Tpo -c -o lib/libcoreutils_a-printf-args.o `test -f 'lib/printf-args.c' || echo './'`lib/printf-args.c lib/printf-args.c: In function 'printf_fetchargs': lib/printf-args.c:45:5: error: enumeration value 'TYPE_NONE' not handled in switch [-Werror=switch-enum] 45 | switch (ap->type) | ^~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:20306: lib/libcoreutils_a-printf-args.o] Error 1 gcc-14 -ftrapv -I. -I./lib -Ilib -I./lib -Isrc -I./src -Werror -fstrict-flex-arrays -Wall -Warith-conversion -Wbad-function-cast -Wcast-align=strict -Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra -Wformat-signedness -Wflex-array-member-not-at-end -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnull-dereference -Wopenmp-simd -Woverlength-strings -Wpacked -Wpointer-arith -Wshadow -Wstrict-flex-arrays -Wstrict-prototypes -Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wtrampolines -Wunknown-pragmas -Wvariadic-macros -Wvla -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wbidi-chars=any,ucn -Wformat=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 -Wuse-after-free=3 -Wunused-const-variable=2 -Wvla-larger-than=4031 -Wswitch-enum -Wno-sign-compare -Wno-unused-parameter -Wno-format-nonliteral -fdiagnostics-show-option -funit-at-a-time -Wno-return-local-addr -Wno-stringop-overflow -Wno-cast-qual -Wno-conversion -Wno-float-equal -Wno-sign-compare -Wno-undef -Wno-unused-function -Wno-unused-parameter -Wno-float-conversion -Wimplicit-fallthrough -Wno-pedantic -Wno-sign-conversion -Wno-type-limits -Wno-unused-const-variable -Wno-unsuffixed-float-constants -g -O2 -MT lib/libcoreutils_a-vasnprintf.o -MD -MP -MF lib/.deps/libcoreutils_a-vasnprintf.Tpo -c -o lib/libcoreutils_a-vasnprintf.o `test -f 'lib/vasnprintf.c' || echo './'`lib/vasnprintf.c lib/vasnprintf.c: In function 'vasnprintf': lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_NONE' not handled in switch [-Werror=switch-enum] 6214 | switch (type) | ^~~~~~ lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_SCHAR' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_UCHAR' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_SHORT' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_USHORT' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_INT' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_UINT' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_INT8_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_UINT8_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_INT16_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_UINT16_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_INT32_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_UINT32_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_INT_FAST8_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_UINT_FAST8_T' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_DOUBLE' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_CHAR' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_STRING' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_SCHAR_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_SHORT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_LONGINT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_LONGLONGINT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT8_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT16_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT32_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT64_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT_FAST8_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT_FAST16_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT_FAST32_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6214:17: error: enumeration value 'TYPE_COUNT_INT_FAST64_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_NONE' not handled in switch [-Werror=switch-enum] 6510 | switch (type) | ^~~~~~ lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_SCHAR_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_SHORT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_LONGINT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_LONGLONGINT_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT8_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT16_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT32_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT64_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT_FAST8_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT_FAST16_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT_FAST32_T_POINTER' not handled in switch [-Werror=switch-enum] lib/vasnprintf.c:6510:21: error: enumeration value 'TYPE_COUNT_INT_FAST64_T_POINTER' not handled in switch [-Werror=switch-enum] cc1: all warnings being treated as errors make[2]: *** [Makefile:20334: lib/libcoreutils_a-vasnprintf.o] Error 1 As said repeatedly on this mailing list: * Gnulib does not support compilation with '-Werror'. * Maintainers of packages that use Gnulib MUST NOT force their personal coding style upon Gnulib, via warning options. So, these compilation units in coreutils MUST be compiled with -Wno-error. This patch achieves that. Previously we had added -Wno-error only on the gnulib tests. This patch adds it also for the source files in lib/. 2025-02-03 Bruno Haible <br...@clisp.org> gnulib-tool: Allow compiler warnings in Gnulib code. * gnulib-tool.sh (func_emit_lib_Makefile_am): Append $(GL_CFLAG_ALLOW_WARNINGS) to the ${libname}_${libext}_CFLAGS variable. * pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): Likewise. diff --git a/gnulib-tool.sh b/gnulib-tool.sh index eedeb306bc..bddd3073d6 100755 --- a/gnulib-tool.sh +++ b/gnulib-tool.sh @@ -4025,8 +4025,22 @@ func_emit_lib_Makefile_am () fi echo echo "${libname}_${libext}_SOURCES =" + # Insert a '-Wno-error' option in the compilation commands emitted by + # Automake, between $(AM_CPPFLAGS) and before the reference to @CFLAGS@. + # Why? + # - Because every package maintainer has their preferred set of warnings + # that they may want to enforce in the main source code of their package, + # and some of these warnings (such as '-Wswitch-enum') complain about code + # that is just perfect. + # Gnulib source code is maintained according to Gnulib coding style. + # Package maintainers have no right to force their coding style upon Gnulib. + # Why before @CFLAGS@? + # - Because "the user is always right": If a user adds '-Werror' to their + # CFLAGS, they have asked for errors, they will get errors. But they have + # no right to complain about these errors, because Gnulib does not support + # '-Werror'. if ! $for_test; then - echo "${libname}_${libext}_CFLAGS = \$(AM_CFLAGS) \$(GL_CFLAG_GNULIB_WARNINGS)" + echo "${libname}_${libext}_CFLAGS = \$(AM_CFLAGS) \$(GL_CFLAG_GNULIB_WARNINGS) \$(GL_CFLAG_ALLOW_WARNINGS)" fi # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However, # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@. @@ -4391,7 +4405,9 @@ func_emit_tests_Makefile_am () # arguments, endless recursions, etc.) that a compiler may warn about, # even with just the normal '-Wall' option. # 2) Because every package maintainer has their preferred set of warnings - # that they may want to enforce in the main source code of their package. + # that they may want to enforce in the main source code of their package, + # and some of these warnings (such as '-Wswitch-enum') complain about code + # that is just perfect. # But Gnulib tests are maintained in Gnulib and don't end up in binaries # that that package installs; therefore it does not make sense for # package maintainers to enforce the absence of warnings on these tests. diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index a8f22ed97c..814ccae571 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -911,8 +911,22 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G emit += '\n' emit += '%s_%s_SOURCES =\n' % (libname, libext) + # Insert a '-Wno-error' option in the compilation commands emitted by + # Automake, between $(AM_CPPFLAGS) and before the reference to @CFLAGS@. + # Why? + # - Because every package maintainer has their preferred set of warnings + # that they may want to enforce in the main source code of their package, + # and some of these warnings (such as '-Wswitch-enum') complain about code + # that is just perfect. + # Gnulib source code is maintained according to Gnulib coding style. + # Package maintainers have no right to force their coding style upon Gnulib. + # Why before @CFLAGS@? + # - Because "the user is always right": If a user adds '-Werror' to their + # CFLAGS, they have asked for errors, they will get errors. But they have + # no right to complain about these errors, because Gnulib does not support + # '-Werror'. if not for_test: - emit += '%s_%s_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)\n' % (libname, libext) + emit += '%s_%s_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS) $(GL_CFLAG_ALLOW_WARNINGS)\n' % (libname, libext) # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However, # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@. emit += '%s_%s_LIBADD = $(%s_%s_%sLIBOBJS)\n' % (libname, libext, macro_prefix, libname, perhapsLT) @@ -1183,7 +1197,9 @@ def tests_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: # arguments, endless recursions, etc.) that a compiler may warn about, # even with just the normal '-Wall' option. # 2) Because every package maintainer has their preferred set of warnings - # that they may want to enforce in the main source code of their package. + # that they may want to enforce in the main source code of their package, + # and some of these warnings (such as '-Wswitch-enum') complain about code + # that is just perfect. # But Gnulib tests are maintained in Gnulib and don't end up in binaries # that that package installs; therefore it does not make sense for # package maintainers to enforce the absence of warnings on these tests.