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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jason Gunthorpe <jgg@xxxxxxxxxxxx>

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@xxxxxxxxxxxx>
---
 CMakeLists.txt                  | 13 +++++++++++++
 buildlib/fixup-include/assert.h | 10 ++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 buildlib/fixup-include/assert.h

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
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux