Re: copy-file: Silence gcc warnings

2023-05-26 Thread Paul Eggert

On 2023-05-26 15:41, Bruno Haible wrote:

Maybe by defining
error and error_at_line as inline functions


They're defined by glibc, no? The definitions might collide. Also, I 
suppose the compiler might not inline them and then we'd get a 
diagnostic anyway.


The basic problem is that the old 'error' API doesn't mix well with 
[[noreturn]] and the like. We could write a new function, "eexit" say, 
that behaves like "error" except it never returns. (I chose the name 
"eexit" so as to not mess up the indenting of existing code.)


Or we could just live with "die", as it works.



Re: copy-file: Silence gcc warnings

2023-05-26 Thread Bruno Haible
Pádraig Brady wrote:
> FWIW grep/coreutils use a die() wrapper to achieve this
> for this common idiom.
> 
> [Link to github.com elided]
https://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=dad7ab0b7

Thanks for the pointer.

Can we do better than that, without a 'die' macro? Maybe by defining
error and error_at_line as inline functions that use __builtin_constant_p
on the first argument?

Bruno






Re: copy-file: Silence gcc warnings

2023-05-26 Thread Pádraig Brady

On 26/05/2023 18:34, Bruno Haible wrote:

In GNU gettext, I see these compilation warnings with gcc 13.1.0:

gcc ... -Wall -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-unsuffixed-float-constants -g -O2 -c copy-file.c  -fPIC -DPIC -o 
.libs/libgettextlib_la-copy-file.o
copy-file.c: In function 'copy_file_preserving':
copy-file.c:192:7: warning: this statement may fall through 
[-Wimplicit-fallthrough=]
   192 |   error (EXIT_FAILURE, errno, _("error while opening %s for 
reading"),
   |   
^~~~
   193 |  quote (src_filename));
   |  ~
copy-file.c:195:5: note: here
   195 | case GL_COPY_ERR_OPEN_BACKUP_WRITE:
   | ^~~~
and so on.


The option -Wimplicit-fallthrough gets added as part of GL_CFLAG_GNULIB_WARNINGS
(collected by gl_CC_GNULIB_WARNINGS in m4/gnulib-common.m4). That explains
why I'm not seeing these warnings in gnulib testdirs.

It's probably too hard to teach gcc that error (EXIT_FAILURE, ...) does not
return but error (0, ...) does return. Therefore just disabling this warning
seems the best action.


FWIW grep/coreutils use a die() wrapper to achieve this
for this common idiom.

https://github.com/coreutils/coreutils/commit/dad7ab0b7

cheers,
Pádraig.