From: Bruno Haible <bruno@clisp.org>
Date: Sat, 3 Jun 2023 09:59:59 +0000 (+0200)
Subject: error: Improve comments.
X-Git-Tag: v1.0~1260
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=11e2d84dc74361786a58d0c0cfdee2e092d43f4a;p=gnulib.git

error: Improve comments.

* lib/error.in.h (__gl_error_call): Add more comments.
---

diff --git a/ChangeLog b/ChangeLog
index fda2ed0e3f..31f76abd4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-06-03  Bruno Haible  <bruno@clisp.org>
+
+	error: Improve comments.
+	* lib/error.in.h (__gl_error_call): Add more comments.
+
 2023-06-02  Paul Eggert  <eggert@cs.ucla.edu>
 
 	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__) \