Message ID | 1505256183-83048-1-git-send-email-yihung.wei@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | [ovs-dev] Fix C++ build issue when static_assert() is not available | expand |
On Tue, Sep 12, 2017 at 03:43:03PM -0700, Yi-Hung Wei wrote: > This patch prevents compile errors if the C++ compiler does not support > C++11 or the support is not enabled. n> > VMWare-BZ: #1953215 > Fixes: 994bfc298502 ("Automatically verify that OVS header files work OK in C++ also.") > Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> Assuming this passes on travis, it looks good to me. I assume you'll backport it as necessary. Thanks a lot! Acked-by: Ben Pfaff <blp@ovn.org>
On Wed, Sep 13, 2017 at 01:27:09PM -0700, Ben Pfaff wrote: > On Tue, Sep 12, 2017 at 03:43:03PM -0700, Yi-Hung Wei wrote: > > This patch prevents compile errors if the C++ compiler does not support > > C++11 or the support is not enabled. > n> > > VMWare-BZ: #1953215 > > Fixes: 994bfc298502 ("Automatically verify that OVS header files work OK in C++ also.") > > Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> > > Assuming this passes on travis, it looks good to me. I assume you'll > backport it as necessary. Thanks a lot! > > Acked-by: Ben Pfaff <blp@ovn.org> You told me that it does pass on travis, so I applied this to master and branch-2.8. Thanks again!
diff --git a/include/openflow/openflow-common.h b/include/openflow/openflow-common.h index d66551997434..ea6bb41bc15c 100644 --- a/include/openflow/openflow-common.h +++ b/include/openflow/openflow-common.h @@ -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 diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h index 0076ad763578..c7cb9308d029 100644 --- a/include/openvswitch/compiler.h +++ b/include/openvswitch/compiler.h @@ -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)
This patch prevents compile errors if the C++ compiler does not support C++11 or the support is not enabled. VMWare-BZ: #1953215 Fixes: 994bfc298502 ("Automatically verify that OVS header files work OK in C++ also.") Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> --- include/openflow/openflow-common.h | 7 +++++-- include/openvswitch/compiler.h | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-)