From: Paul Eggert Date: Sat, 3 Jun 2023 05:30:52 +0000 (-0700) Subject: error: do not evaluate status twice X-Git-Tag: v1.0~1261 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cfd41b3ac199a4f95fb78ee251e8c8a7c6f86ad1;p=thirdparty%2Fgnulib.git error: do not evaluate status twice Do this in a different way, so that the status is evaluated once even when not optimizing and when using GCC. * lib/error.in.h (__gl_error_call1) [__GNUC__]: New macro. (__gl_error_call) [__GNUC__]: Use it. --- diff --git a/ChangeLog b/ChangeLog index 3187128c1f..fda2ed0e3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-06-02 Paul Eggert + + error: do not evaluate status twice + Do this in a different way, so that the status is evaluated + once even when not optimizing and when using GCC. + * lib/error.in.h (__gl_error_call1) [__GNUC__]: New macro. + (__gl_error_call) [__GNUC__]: Use it. + 2023-06-02 Bruno Haible warnings: Add ability to inhibit all warnings. diff --git a/lib/error.in.h b/lib/error.in.h index f37dba170c..279258f63e 100644 --- a/lib/error.in.h +++ b/lib/error.in.h @@ -50,23 +50,20 @@ #endif /* Helper macro for supporting the compiler's control flow analysis better. + It evaluates its arguments only once. It uses __builtin_constant_p + and comma expressions to work around GCC false positives. Test case: Compile copy-file.c with "gcc -Wimplicit-fallthrough". */ #ifdef __GNUC__ -/* Avoid evaluating STATUS twice, if this is possible without making the - "warning: this statement may fall through" reappear. */ -# if __OPTIMIZE__ -# define __gl_error_call(function, status, ...) \ - ({ \ - int const __errstatus = (status); \ - (function) (__errstatus, __VA_ARGS__); \ - __errstatus != 0 ? unreachable () : (void) 0; \ - }) -# else -# define __gl_error_call(function, status, ...) \ - ((function) (status, __VA_ARGS__), \ - (status) != 0 ? unreachable () : (void)0 \ - ) -# endif +# define __gl_error_call1(function, status, ...) \ + ((function) (status, __VA_ARGS__), \ + (status) != 0 ? unreachable () : (void) 0) +# define __gl_error_call(function, status, ...) \ + (__builtin_constant_p (status) \ + ? __gl_error_call1 (function, status, __VA_ARGS__) \ + : ({ \ + int const __errstatus = status; \ + __gl_error_call1 (function, __errstatus, __VA_ARGS__); \ + })) #else # define __gl_error_call(function, status, ...) \ (function) (status, __VA_ARGS__)