2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-27 15:18:06 +00:00

Fix C++ build issue when static_assert() is not available

This patch prevents compile errors if the C++ compiler does not support
C++11 or the support is not enabled.

VMWare-BZ: #1953215
Fixes: 994bfc2985 ("Automatically verify that OVS header files work OK in C++ also.")
Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Yi-Hung Wei
2017-09-12 15:43:03 -07:00
committed by Ben Pfaff
parent 4a0a2c24a4
commit 5e8bed8373
2 changed files with 10 additions and 3 deletions

View File

@@ -59,9 +59,12 @@
#define OFP_ASSERT(EXPR) \
extern int (*build_assert(void))[ sizeof(struct { \
unsigned int build_assert_failed : (EXPR) ? 1 : -1; })]
#else /* __cplusplus */
#elif __cplusplus >= 201103L
#define OFP_ASSERT(EXPR) static_assert(EXPR, "assertion failed")
#endif /* __cplusplus */
#else /* __cplusplus < 201103L */
#include <boost/static_assert.hpp>
#define OFP_ASSERT BOOST_STATIC_ASSERT
#endif /* __cplusplus < 201103L */
/* Version number:
* Non-experimental versions released: 0x01 0x02

View File

@@ -243,9 +243,13 @@
#ifdef __CHECKER__
#define BUILD_ASSERT(EXPR) ((void) 0)
#define BUILD_ASSERT_DECL(EXPR) extern int (*build_assert(void))[1]
#elif defined(__cplusplus)
#elif defined(__cplusplus) && __cplusplus >= 201103L
#define BUILD_ASSERT(EXPR) static_assert(EXPR, "assertion failed")
#define BUILD_ASSERT_DECL(EXPR) static_assert(EXPR, "assertion failed")
#elif defined(__cplusplus) && __cplusplus < 201103L
#include <boost/static_assert.hpp>
#define BUILD_ASSERT BOOST_STATIC_ASSERT
#define BUILD_ASSERT_DECL BOOST_STATIC_ASSERT
#elif (__GNUC__ * 256 + __GNUC_MINOR__ >= 0x403 \
|| __has_extension(c_static_assert))
#define BUILD_ASSERT_DECL(EXPR) _Static_assert(EXPR, #EXPR)