]> Savannah Git Hosting - gnulib.git/commitdiff
error: Avoid implicit-fallthrough warnings with -O0 (regr. 2023-05-30).
authorBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 18:02:45 +0000 (20:02 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 18:02:45 +0000 (20:02 +0200)
* lib/error.in.h (__gl_error_call): Parenthesize status. When not
optimizing, expand to code without compound statements.

ChangeLog
lib/error.in.h

index b48ca091ce26ade5addbc7328f3cebcec1c178e7..869096eb4192d16bc60c990ec6ffe54591796905 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-06-02  Bruno Haible  <bruno@clisp.org>
+
+       error: Avoid implicit-fallthrough warnings with -O0 (regr. 2023-05-30).
+       * lib/error.in.h (__gl_error_call): Parenthesize status. When not
+       optimizing, expand to code without compound statements.
+
 2023-06-01  Bruno Haible  <bruno@clisp.org>
 
        getprogname: Add support for ASCII-compatible environments in z/OS.
index f1ba94577b60171bfaf4177d9de433a9563aea58..f37dba170c8ec90139bf2d783c816fa12234b3de 100644 (file)
 # define _GL_ATTRIBUTE_SPEC_PRINTF_ERROR _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM
 #endif
 
+/* Helper macro for supporting the compiler's control flow analysis better.
+   Test case: Compile copy-file.c with "gcc -Wimplicit-fallthrough".  */
 #ifdef __GNUC__
-# define __gl_error_call(function, status, ...) \
-    ({ \
-       int const __errstatus = status; \
-       (function) (__errstatus, __VA_ARGS__); \
-       __errstatus != 0 ? unreachable () : (void) 0; \
-    })
+/* 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
 #else
 # define __gl_error_call(function, status, ...) \
     (function) (status, __VA_ARGS__)