]> Savannah Git Hosting - gnulib.git/commitdiff
assert-h, verify: Fix compilation error in C++ mode with MSVC 14.30.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Apr 2023 06:42:56 +0000 (08:42 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 21 Apr 2023 15:28:48 +0000 (17:28 +0200)
* lib/verify.h (_Static_assert): In C++ mode with MSVC 14.1 or newer,
define merely to static_assert.
(static_assert): In C++ mode with MSVC 14.1 or newer, don't define.

ChangeLog
lib/verify.h

index 4960e5530553b78def6d6d84d84228963a35a53c..134199a79fa7ff6384ed4511a703cfc5300adf38 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-04-20  Bruno Haible  <bruno@clisp.org>
+
+       assert-h, verify: Fix compilation error in C++ mode with MSVC 14.30.
+       * lib/verify.h (_Static_assert): In C++ mode with MSVC 14.1 or newer,
+       define merely to static_assert.
+       (static_assert): In C++ mode with MSVC 14.1 or newer, don't define.
+
 2023-04-19  Bruno Haible  <bruno@clisp.org>
 
        chown, lchown tests: Fix link error on mingw 10.
index ec0a41eb9c49a507a5bd21fae9056df679d1f9d6..14d5658d276cc62351fa021d8e5f9d29e470cf11 100644 (file)
@@ -241,17 +241,23 @@ template <int w>
 #   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", -)
+#   if defined __cplusplus && _MSC_VER >= 1910
+     /* In MSVC 14.1 or newer, static_assert accepts one or two arguments,
+        but _Static_assert is not defined.  */
+#    define _Static_assert static_assert
+#   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
 # endif
 /* Define static_assert if needed.  */
 # if (!defined static_assert \
       && (!defined __cplusplus \
           || (__cpp_static_assert < 201411 \
-              && __GNUG__ < 6 && __clang_major__ < 6)))
+              && __GNUG__ < 6 && __clang_major__ < 6 && _MSC_VER < 1910)))
 #  if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
 /* 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.