]> Savannah Git Hosting - gnulib.git/commitdiff
assert-h: port static_assert to strict C99
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Dec 2022 22:15:43 +0000 (14:15 -0800)
committerBruno Haible <bruno@clisp.org>
Sun, 1 Jan 2023 09:27:38 +0000 (10:27 +0100)
* lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
42.56: 1506-041 (E) The invocation of macro _Static_assert
contains fewer arguments than are required by the macro
definition.’  This diagnostic is valid because C99 requires
that if you #define _Static_assert(R, ...) you must call
_Static_assert with at least two arguments.  I found a similar
problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.

ChangeLog
lib/verify.h

index 49744cad871bf6df5c94e5c290b2f3377c5fee07..d79aadb855bdcd12826b8af396c11067cde6325c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2022-12-28  Paul Eggert  <eggert@cs.ucla.edu>
+
+       assert-h: port static_assert to strict C99
+       * lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
+       Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
+       V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
+       42.56: 1506-041 (E) The invocation of macro _Static_assert
+       contains fewer arguments than are required by the macro
+       definition.’  This diagnostic is valid because C99 requires
+       that if you #define _Static_assert(R, ...) you must call
+       _Static_assert with at least two arguments.  I found a similar
+       problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.
+
 2022-12-27  Bruno Haible  <bruno@clisp.org>
 
        Fix compilation errors in C++ mode on Solaris 11 OpenIndiana.
index 42307c0be6bfabdd4dac74aa7cf5021c32cf7e07..657c5f916d227581ae4a939a8c3938a92ec1ed30 100644 (file)
@@ -220,8 +220,15 @@ template <int w>
 /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
 #ifdef _GL_STATIC_ASSERT_H
 # if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
-#  define _Static_assert(R, ...) \
-     _GL_VERIFY ((R), "static assertion failed", -)
+#  if !defined _MSC_VER || defined __clang__
+#   define _Static_assert(...) \
+      _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+#  else
+    /* Work around MSVC preprocessor incompatibility with ISO C; see
+       <https://stackoverflow.com/questions/5134523/>.  */
+#   define _Static_assert(R, ...) \
+      _GL_VERIFY ((R), "static assertion failed", -)
+#  endif
 # endif
 # if (!defined static_assert \
       && (!defined __cplusplus \
@@ -231,9 +238,8 @@ template <int w>
 /* MSVC 14 in C++ mode supports the two-arguments static_assert but not
    the one-argument static_assert, and it does not support _Static_assert.
    We have to play preprocessor tricks to distinguish the two cases.
-   Since the MSVC preprocessor is not ISO C compliant (cf.
-   <https://stackoverflow.com/questions/5134523/>), the solution is specific
-   to MSVC.  */
+   Since the MSVC preprocessor is not ISO C compliant (see above),.
+   the solution is specific to MSVC.  */
 #   define _GL_EXPAND(x) x
 #   define _GL_SA1(a1) static_assert ((a1), "static assertion failed")
 #   define _GL_SA2 static_assert