]> Savannah Git Hosting - gnulib.git/commitdiff
assert-h, verify: Fix conflict with standard C++ header files on macOS.
authorBruno Haible <bruno@clisp.org>
Sat, 4 Feb 2023 13:31:08 +0000 (14:31 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 4 Feb 2023 13:31:08 +0000 (14:31 +0100)
* lib/verify.h (_Static_assert): Don't redefine with clang ≥ 3.8.0
in C++ mode.
* tests/test-assert-h-c++.cc: Also check against conflict with the
standard C++ header files.
* tests/test-assert-h-c++2.cc: Likewise.

ChangeLog
lib/verify.h
tests/test-assert-h-c++.cc
tests/test-assert-h-c++2.cc

index 6ef50965e9deb7031ea777e6546f6d202ef4a109..0f8b53ff132f43a840df43ef94c78424cb6d0b64 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-02-04  Bruno Haible  <bruno@clisp.org>
+
+       assert-h, verify: Fix conflict with standard C++ header files on macOS.
+       * lib/verify.h (_Static_assert): Don't redefine with clang ≥ 3.8.0
+       in C++ mode.
+       * tests/test-assert-h-c++.cc: Also check against conflict with the
+       standard C++ header files.
+       * tests/test-assert-h-c++2.cc: Likewise.
+
 2023-02-04  Bruno Haible  <bruno@clisp.org>
 
        Activate all existing C++ tests.
index b63cb264321f142958980326dbca9f8436de1505..8f786af7f5ae8e2e71d2c411604aad406bc7a86b 100644 (file)
@@ -222,7 +222,21 @@ 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 if needed.  */
+/* With clang ≥ 3.8.0 in C++ mode, _Static_assert already works and accepts
+   1 or 2 arguments.  We better don't override it, because clang's standard
+   C++ library uses static_assert inside classes in several places, and our
+   replacement via _GL_VERIFY does not work in these contexts.  */
+# if (defined __cplusplus && defined __clang__ \
+      && (4 <= __clang_major__ + (8 <= __clang_minor__)))
+#  if 5 <= __clang_major__
+/* Avoid "warning: 'static_assert' with no message is a C++17 extension".  */
+#   pragma clang diagnostic ignored "-Wc++17-extensions"
+#  else
+/* Avoid "warning: static_assert with no message is a C++1z extension".  */
+#   pragma clang diagnostic ignored "-Wc++1z-extensions"
+#  endif
+# elif !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
 #  if !defined _MSC_VER || defined __clang__
 #   define _Static_assert(...) \
       _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
@@ -233,6 +247,7 @@ template <int w>
       _GL_VERIFY ((R), "static assertion failed", -)
 #  endif
 # endif
+/* Define static_assert if needed.  */
 # if (!defined static_assert \
       && __STDC_VERSION__ < 202311 \
       && (!defined __cplusplus \
index 4fa23bfeec9d0ec892cfa92f1731455546f64eec..6b76565633960469664e4c139ffe0ab58e425b5e 100644 (file)
 
 #include <assert.h>
 
+/* Check against conflicts between <assert.h> and the C++ header files.  */
+#include <stddef.h>
+#include <iostream>
+
 
 int
 main ()
index 3c19de325cdfc04f4e896ad84d6d8545a0b2d029..ffd7c8cf9261c23ebd72fc7e275e4c224ddb1674 100644 (file)
@@ -18,3 +18,7 @@
 #include <config.h>
 
 #include <cassert>
+
+/* Check against conflicts between <cassert> and other C++ header files.  */
+#include <stddef.h>
+#include <iostream>