More robust static_assert
#include <assert.h>
-#ifndef static_assert
-
+/* Handle clang */
#ifndef __has_feature
#define __has_feature(x) 0
#endif
-#if __has_feature(c_static_assert)
+#if defined(static_assert)
+#ifndef __static_assert_is_defined
+#define __static_assert_is_defined 1
+#endif
+#endif
+/* Handle static_assert as a keyword in C++ and compiler specifics. */
+#if !defined(__static_assert_is_defined)
+
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __static_assert_is_defined 1
+#elif defined(__cplusplus) && __has_feature(cxx_static_assert)
+#define __static_assert_is_defined 1
+#elif defined(_MSC_VER) && (_MSC_VER >= 1600)
+#define __static_assert_is_defined 1
+#elif __has_feature(c_static_assert)
+#define static_assert(pred, msg) _Static_assert(pred, msg)
+#define __static_assert_is_defined 1
+#elif defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+/* In case the clib headers are not compliant. */
#define static_assert(pred, msg) _Static_assert(pred, msg)
+#define __static_assert_is_defined 1
+#endif
+
+#endif /* __static_assert_is_defined */
-#else
+
+#if !defined(__static_assert_is_defined)
#define __PSTATIC_ASSERT_CONCAT_(a, b) static_assert_scope_##a##_line_##b
#define __PSTATIC_ASSERT_CONCAT(a, b) __PSTATIC_ASSERT_CONCAT_(a, b)
#define static_assert(e, msg) enum { __PSTATIC_ASSERT_CONCAT(__PSTATIC_ASSERT_COUNTER, __LINE__) = 1/(!!(e)) }
#endif
-#endif /* __has_feature */
-#endif /* static_assert */
+#define __static_assert_is_defined 1
+
+#endif /* __static_assert_is_defined */
#endif /* PSTATIC_ASSERT_H */
