From 11e2d84dc74361786a58d0c0cfdee2e092d43f4a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 3 Jun 2023 11:59:59 +0200 Subject: [PATCH] error: Improve comments. * lib/error.in.h (__gl_error_call): Add more comments. --- ChangeLog | 5 +++++ lib/error.in.h | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fda2ed0e3f..31f76abd4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-06-03 Bruno Haible + + error: Improve comments. + * lib/error.in.h (__gl_error_call): Add more comments. + 2023-06-02 Paul Eggert error: do not evaluate status twice diff --git a/lib/error.in.h b/lib/error.in.h index 279258f63e..ef4b3c3815 100644 --- a/lib/error.in.h +++ b/lib/error.in.h @@ -50,13 +50,21 @@ #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. + It evaluates its arguments only once. Test case: Compile copy-file.c with "gcc -Wimplicit-fallthrough". */ #ifdef __GNUC__ +/* Use 'unreachable' to tell the compiler when the function call does not + return. */ # define __gl_error_call1(function, status, ...) \ ((function) (status, __VA_ARGS__), \ (status) != 0 ? unreachable () : (void) 0) +/* If STATUS is a not a constant, the function call may or may not return; + therefore -Wimplicit-fallthrough will produce a warning. Use a compound + statement in order to evaluate STATUS only once. + If STATUS is a constant, we don't use a compound statement, because that + would trigger a -Wimplicit-fallthrough warning even when STATUS is != 0, + when not optimizing. This causes STATUS to be evaluated twice, but + that's OK since it does not have side effects. */ # define __gl_error_call(function, status, ...) \ (__builtin_constant_p (status) \ ? __gl_error_call1 (function, status, __VA_ARGS__) \ -- 2.39.5