]> Savannah Git Hosting - gnulib.git/commitdiff
Use statement-expressions without warnings, even in strict ISO C mode.
authorBruno Haible <bruno@clisp.org>
Mon, 4 Sep 2023 19:54:09 +0000 (21:54 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 14 Sep 2023 09:42:03 +0000 (11:42 +0200)
Suggested by Eric Blake <eblake@redhat.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-09/msg00025.html>.

* lib/error.in.h (__gl_error_call): Use the variant with obvious control
flow also with clang. Use '__extension__' to avoid -Wpedantic warnings.
* lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Define as
macros even when __STRICT_ANSI__ is defined. But use '__extension__' to
avoid -Wpedantic warnings.
* lib/setenv.c (KNOWN_VALUE): Use '__extension__' to avoid -Wpedantic
warnings.
* lib/xalloc-oversized.h (xalloc_oversized): Use optimized variant even
when __STRICT_ANSI__ is defined. But use '__extension__' to avoid
-Wpedantic warnings.

ChangeLog
lib/error.in.h
lib/math.in.h
lib/setenv.c
lib/xalloc-oversized.h

index ae86e808ad42746210fb164a41d162bb87b9c202..4a762853e198ab327abe79eb73e76f92103d526f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-09-04  Bruno Haible  <bruno@clisp.org>
+
+       Use statement-expressions without warnings, even in strict ISO C mode.
+       Suggested by Eric Blake <eblake@redhat.com> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2023-09/msg00025.html>.
+       * lib/error.in.h (__gl_error_call): Use the variant with obvious control
+       flow also with clang. Use '__extension__' to avoid -Wpedantic warnings.
+       * lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Define as
+       macros even when __STRICT_ANSI__ is defined. But use '__extension__' to
+       avoid -Wpedantic warnings.
+       * lib/setenv.c (KNOWN_VALUE): Use '__extension__' to avoid -Wpedantic
+       warnings.
+       * lib/xalloc-oversized.h (xalloc_oversized): Use optimized variant even
+       when __STRICT_ANSI__ is defined. But use '__extension__' to avoid
+       -Wpedantic warnings.
+
 2023-09-04  Bruno Haible  <bruno@clisp.org>
 
        Fix some g++ warnings "has a different exception specifier".
index 94477fde08b697b02f97146562b39013822e7deb..61f98c5216847cb03e6485d9bdf5519c32b37c54 100644 (file)
@@ -53,7 +53,7 @@
 /* Helper macro for supporting the compiler's control flow analysis better.
    It evaluates its arguments only once.
    Test case: Compile copy-file.c with "gcc -Wimplicit-fallthrough".  */
-#ifdef __GNUC__
+#if defined __GNUC__ || defined __clang__
 /* Use 'unreachable' to tell the compiler when the function call does not
    return.  */
 # define __gl_error_call1(function, status, ...) \
    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__) \
-     : ({ \
-         int const __errstatus = status; \
+# define __gl_error_call(function, status, ...)                 \
+    (__builtin_constant_p (status)                              \
+     ? __gl_error_call1 (function, status, __VA_ARGS__)         \
+     : __extension__                                            \
+       ({                                                       \
+         int const __errstatus = status;                        \
          __gl_error_call1 (function, __errstatus, __VA_ARGS__); \
        }))
 #else
index 117bc993b55adc29d8ea22a4a683b45ac6c00c0b..75d5013cf1025bf02abf49251f15f5efa2415d1a 100644 (file)
@@ -2695,12 +2695,13 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
 _GL_EXTERN_C int gl_signbitf (float arg);
 _GL_EXTERN_C int gl_signbitd (double arg);
 _GL_EXTERN_C int gl_signbitl (long double arg);
-#  if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
+#  if __GNUC__ >= 2 || defined __clang__
 #   define _GL_NUM_UINT_WORDS(type) \
       ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
 #    define gl_signbitf_OPTIMIZED_MACRO
 #    define gl_signbitf(arg) \
+       __extension__                                                    \
        ({ union { float _value;                                         \
                   unsigned int _word[_GL_NUM_UINT_WORDS (float)];       \
                 } _m;                                                   \
@@ -2711,6 +2712,7 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
 #    define gl_signbitd_OPTIMIZED_MACRO
 #    define gl_signbitd(arg) \
+       __extension__                                                    \
        ({ union { double _value;                                        \
                   unsigned int _word[_GL_NUM_UINT_WORDS (double)];      \
                 } _m;                                                   \
@@ -2721,6 +2723,7 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
 #    define gl_signbitl_OPTIMIZED_MACRO
 #    define gl_signbitl(arg) \
+       __extension__                                                    \
        ({ union { long double _value;                                   \
                   unsigned int _word[_GL_NUM_UINT_WORDS (long double)]; \
                 } _m;                                                   \
index 22b12fd01845f6df374f22d0e6ba69c00665786c..706a032a49132556f1ae33b52cc76af08cf5a3ed 100644 (file)
@@ -82,6 +82,7 @@ typedef int (*compar_fn_t) (const void *, const void *);
 static void *known_values;
 
 # define KNOWN_VALUE(Str) \
+  __extension__                                                               \
   ({                                                                          \
     void *value = tfind (Str, &known_values, (compar_fn_t) strcmp);           \
     value != NULL ? *(char **) value : NULL;                                  \
index 5dbdfb5506aa7355de2b305a9b0dda3c8d4e256c..483bd117961a50331a9c0faa49d9d8a77a87bfa6 100644 (file)
 #if 7 <= __GNUC__ && !defined __clang__ && PTRDIFF_MAX < SIZE_MAX
 # define xalloc_oversized(n, s) \
    __builtin_mul_overflow_p (n, s, (ptrdiff_t) 1)
-#elif (5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ \
-       && PTRDIFF_MAX < SIZE_MAX)
+#elif 5 <= __GNUC__ && !defined __ICC && PTRDIFF_MAX < SIZE_MAX
 # define xalloc_oversized(n, s) \
    (__builtin_constant_p (n) && __builtin_constant_p (s) \
     ? __xalloc_oversized (n, s) \
-    : ({ ptrdiff_t __xalloc_count; \
-         __builtin_mul_overflow (n, s, &__xalloc_count); }))
+    : __extension__ \
+        ({ ptrdiff_t __xalloc_count; \
+           __builtin_mul_overflow (n, s, &__xalloc_count); }))
 
 /* Other compilers use integer division; this may be slower but is
    more portable.  */