Skip to content

Commit

Permalink
Automatically verify that OVS header files work OK in C++ also.
Browse files Browse the repository at this point in the history
This should help address a recurring problem.

This change makes the OVS header files, when parsed by a C++ compiler,
require C++11 or later.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Russell Bryant <[email protected]>
  • Loading branch information
blp committed Jul 31, 2017
1 parent 4d617a8 commit 994bfc2
Show file tree
Hide file tree
Showing 7 changed files with 1,018 additions and 5 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ MAN_ROOTS =
noinst_DATA =
noinst_HEADERS =
lib_LTLIBRARIES =
noinst_LTLIBRARIES =
noinst_man_MANS =
noinst_PROGRAMS =
noinst_SCRIPTS =
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ AM_INIT_AUTOMAKE([tar-pax])

AC_PROG_CC_C99
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_CPP
AC_PROG_MKDIR_P
AC_PROG_FGREP
Expand Down Expand Up @@ -135,6 +136,7 @@ OVS_CHECK_POSIX_AIO
OVS_CHECK_PTHREAD_SET_NAME
OVS_CHECK_LINUX_HOST
OVS_LIBTOOL_VERSIONS
OVS_CHECK_CXX
AX_FUNC_POSIX_MEMALIGN

OVS_CHECK_INCLUDE_NEXT([stdio.h string.h])
Expand Down
3 changes: 1 addition & 2 deletions include/openflow/openflow-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
extern int (*build_assert(void))[ sizeof(struct { \
unsigned int build_assert_failed : (EXPR) ? 1 : -1; })]
#else /* __cplusplus */
#include <boost/static_assert.hpp>
#define OFP_ASSERT BOOST_STATIC_ASSERT
#define OFP_ASSERT(EXPR) static_assert(EXPR, "assertion failed")
#endif /* __cplusplus */

/* Version number:
Expand Down
14 changes: 14 additions & 0 deletions include/openvswitch/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ openvswitchinclude_HEADERS = \
include/openvswitch/version.h \
include/openvswitch/vconn.h \
include/openvswitch/vlog.h

if HAVE_CXX
# OVS does not use C++ itself, but it provides public header files
# that a C++ compiler should accept, so when --enable-Werror is in
# effect and a C++ compiler is available, we build a C++ source file
# that #includes all the public headers, as a way to ensure that they
# are acceptable as C++.
noinst_LTLIBRARIES += include/openvswitch/libcxxtest.la
nodist_include_openvswitch_libcxxtest_la_SOURCES = include/openvswitch/cxxtest.cc
include/openvswitch/cxxtest.cc: include/openvswitch/automake.mk
$(AM_V_GEN)for header in $(openvswitchinclude_HEADERS); do \
echo $$header; \
done | sed 's,^include/\(.*\)$$,#include <\1>,' > $@
endif
5 changes: 2 additions & 3 deletions include/openvswitch/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@
#define BUILD_ASSERT(EXPR) ((void) 0)
#define BUILD_ASSERT_DECL(EXPR) extern int (*build_assert(void))[1]
#elif defined(__cplusplus)
#include <boost/static_assert.hpp>
#define BUILD_ASSERT BOOST_STATIC_ASSERT
#define BUILD_ASSERT_DECL BOOST_STATIC_ASSERT
#define BUILD_ASSERT(EXPR) static_assert(EXPR, "assertion failed")
#define BUILD_ASSERT_DECL(EXPR) static_assert(EXPR, "assertion failed")
#elif (__GNUC__ * 256 + __GNUC_MINOR__ >= 0x403 \
|| __has_extension(c_static_assert))
#define BUILD_ASSERT_DECL(EXPR) _Static_assert(EXPR, #EXPR)
Expand Down
Loading

0 comments on commit 994bfc2

Please sign in to comment.