diff mbox

[rdma-core,4/8] Allow static_assert to be used

Message ID 20180313220737.4336-5-jgg@ziepe.ca (mailing list archive)
State Not Applicable
Delegated to: shefty
Headers show

Commit Message

Jason Gunthorpe March 13, 2018, 10:07 p.m. UTC
From: Jason Gunthorpe <jgg@mellanox.com>

There are some places where this is just the simplest solution and
we don't care if all compilers support the check. Provide a shim
for old compilers.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
---
 CMakeLists.txt                  | 13 +++++++++++++
 buildlib/fixup-include/assert.h | 10 ++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 buildlib/fixup-include/assert.h
diff mbox

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f458efbda5a19..47b2dd8b823e86 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -405,6 +405,16 @@  if (NOT LIBC_HAS_LIBRT)
   set(RT_LIBRARIES "rt")
 endif()
 
+# Check for static_assert
+CHECK_C_SOURCE_COMPILES("
+#include <assert.h>
+static_assert(1, \"failed\");
+int main(int argc,const char *argv[]) {
+   static_assert(1, \"failed\");
+   return 0;
+};" HAVE_STATIC_ASSERT)
+RDMA_DoFixup("${HAVE_STATIC_ASSERT}" "assert.h")
+
 #-------------------------
 # Final warning flags
 
@@ -521,6 +531,9 @@  endif()
 if (NOT HAVE_STDATOMIC)
   message(STATUS " C11 stdatomic.h NOT available (old compiler)")
 endif()
+if (NOT HAVE_STATIC_ASSERT)
+  message(STATUS " C11 static_assert NOT available (old compiler)")
+endif()
 if (NOT HAVE_VALGRIND_MEMCHECK)
   message(STATUS " Valgrind memcheck.h NOT enabled")
 endif()
diff --git a/buildlib/fixup-include/assert.h b/buildlib/fixup-include/assert.h
new file mode 100644
index 00000000000000..848c9310c1ff2a
--- /dev/null
+++ b/buildlib/fixup-include/assert.h
@@ -0,0 +1,10 @@ 
+#ifndef _FIXUP_ASSERT_H
+#define _FIXUP_ASSERT_H
+
+#include_next <assert.h>
+
+/* Without C11 compiler support it is not possible to implement static_assert */
+#undef static_assert
+#define static_assert(_cond, msg)
+
+#endif