]> Savannah Git Hosting - gnulib.git/commitdiff
verify: Make assume work on bit field expressions (regr. 2020-08-22).
authorBruno Haible <bruno@clisp.org>
Sun, 23 Aug 2020 14:24:55 +0000 (16:24 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 23 Aug 2020 14:24:55 +0000 (16:24 +0200)
Reported by Benno Schulenberg <bensberg@telfort.nl> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-08/msg00202.html>.

* lib/verify.h (assume): Use '_Bool' or 'bool' as type of the temporary
variable.

ChangeLog
lib/verify.h

index 5ff9ccf6efe97a332a3d779a797ad50aaa02caf4..33d4dc0f7ae861204254a3659440e15a0b3ffbd4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-08-23  Bruno Haible  <bruno@clisp.org>
+
+       verify: Make assume work on bit field expressions (regr. 2020-08-22).
+       Reported by Benno Schulenberg <bensberg@telfort.nl> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-08/msg00202.html>.
+       * lib/verify.h (assume): Use '_Bool' or 'bool' as type of the temporary
+       variable.
+
 2020-08-23  Bruno Haible  <bruno@clisp.org>
 
        libc-config: Improve comments.
index 04bb2dfc334d36db4bbd69b40036bfb8982e1480..6d7b961db717679616ee12ecb3f61c28f9e48374 100644 (file)
@@ -322,10 +322,19 @@ template <int w>
 #if _GL_HAS_BUILTIN_ASSUME
 /* Use a temporary variable, to avoid a clang warning
    "the argument to '__builtin_assume' has side effects that will be discarded"
-   if R contains invocations of functions not marked as 'const'.  */
-# define assume(R) \
-    ((void) ({ __typeof__ (R) _gl_verify_temp = (R); \
-               __builtin_assume (_gl_verify_temp); }))
+   if R contains invocations of functions not marked as 'const'.
+   The type of the temporary variable can't be __typeof__ (R), because that
+   does not work on bit field expressions.  Use '_Bool' or 'bool' as type
+   instead.  */
+# if defined __cplusplus
+#  define assume(R) \
+     ((void) ({ bool _gl_verify_temp = (R); \
+                __builtin_assume (_gl_verify_temp); }))
+# else
+#  define assume(R) \
+     ((void) ({ _Bool _gl_verify_temp = (R); \
+                __builtin_assume (_gl_verify_temp); }))
+# endif
 #elif _GL_HAS_BUILTIN_UNREACHABLE
 # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
 #elif 1200 <= _MSC_VER