Pádraig Brady wrote: > >> We might need to cast STATUS to bool to avoid the > >> following failure from coreutils CI:
What you call a failure is in fact a warning. Adding -Werror is your responsibility. > >> In file included from src/die.h:22, > >> from src/chroot.c:27: > >> src/chroot.c: In function 'main': > >> src/chroot.c:362:25: error: '?:'using integer constants in boolean context > >> [-Werror=int-in-bool-context] > >> 362 | error (warn ? 0 : EXIT_CANCELED, 0, "%s", (err)); > >> ./lib/error.h:422:33: note: in definition of macro 'error' > >> 422 | ((error)(0, __VA_ARGS__), (status) ? exit (status) : > >> (void)0) > >> | ^~~~~~ > > > > Actually casting with (bool), or using !! does NOT help here. > To avoid this one can use `(status) != 0`. What this code is meant to do is to test status against 0. Writing it like this is the obvious fix. Done as shown below. > There still is a gotcha (hit in dd.c in coreutils) > where if you define an error macro yourself > you get a macro redefinition error, You can #define _GL_NO_INLINE_ERROR if you don't like gnulib's override. 2023-05-28 Bruno Haible <br...@clisp.org> error: Avoid -Wint-in-bool-context warning. Reported by Pádraig Brady in <https://lists.gnu.org/archive/html/bug-gnulib/2023-05/msg00178.html>. * lib/error.in.h (error, error_at_line): Use 'status != 0', since status is expected to be an int, not a bool value. diff --git a/lib/error.in.h b/lib/error.in.h index 4bf191e102..70fb132133 100644 --- a/lib/error.in.h +++ b/lib/error.in.h @@ -69,7 +69,7 @@ _GL_CXXALIAS_RPL (error, void, # ifndef _GL_NO_INLINE_ERROR # undef error # define error(status, ...) \ - ((rpl_error)(0, __VA_ARGS__), (status) ? exit (status) : (void)0) + ((rpl_error)(0, __VA_ARGS__), (status) != 0 ? exit (status) : (void)0) # endif #else # if ! @HAVE_ERROR@ @@ -81,7 +81,7 @@ _GL_CXXALIAS_SYS (error, void, (int __status, int __errnum, const char *__format, ...)); # ifndef _GL_NO_INLINE_ERROR # define error(status, ...) \ - ((error)(0, __VA_ARGS__), (status) ? exit (status) : (void)0) + ((error)(0, __VA_ARGS__), (status) != 0 ? exit (status) : (void)0) # endif #endif #if __GLIBC__ >= 2 @@ -105,7 +105,7 @@ _GL_CXXALIAS_RPL (error_at_line, void, # ifndef _GL_NO_INLINE_ERROR # undef error_at_line # define error_at_line(status, ...) \ - ((rpl_error_at_line)(0, __VA_ARGS__), (status) ? exit (status) : (void)0) + ((rpl_error_at_line)(0, __VA_ARGS__), (status) != 0 ? exit (status) : (void)0) # endif #else # if ! @HAVE_ERROR_AT_LINE@ @@ -119,7 +119,7 @@ _GL_CXXALIAS_SYS (error_at_line, void, unsigned int __lineno, const char *__format, ...)); # ifndef _GL_NO_INLINE_ERROR # define error_at_line(status, ...) \ - ((error_at_line)(0, __VA_ARGS__), (status) ? exit (status) : (void)0) + ((error_at_line)(0, __VA_ARGS__), (status) != 0 ? exit (status) : (void)0) # endif #endif _GL_CXXALIASWARN (error_at_line);