Skip to content

Commit

Permalink
Fix compile issues of unit tests with gcc5.* on ubuntu 16.04
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhangyi committed Sep 18, 2017
1 parent c0124ec commit a6109be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 1 addition & 7 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NEED_GTEST=1
NEED_GMOCK=1
include ../config.mk
CPPFLAGS+=-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
CPPFLAGS+=-DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES
CPPFLAGS+=-DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES --include sstream_workaround.h
CXXFLAGS+=$(CPPFLAGS) -g -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -std=c++0x

#required by butil/crc32.cc to boost performance for 10x
Expand Down Expand Up @@ -46,7 +46,6 @@ TEST_BUTIL_SOURCES = \
dir_reader_posix_unittest.cc \
file_path_unittest.cc \
file_unittest.cc \
path_service_unittest.cc \
scoped_temp_dir_unittest.cc \
guid_unittest.cc \
hash_unittest.cc \
Expand All @@ -62,8 +61,6 @@ TEST_BUTIL_SOURCES = \
weak_ptr_unittest.cc \
observer_list_unittest.cc \
file_descriptor_shuffle_unittest.cc \
process_metrics_unittest.cc \
process_util_unittest.cc \
rand_util_unittest.cc \
safe_numerics_unittest.cc \
scoped_clear_errno_unittest.cc \
Expand Down Expand Up @@ -104,7 +101,6 @@ TEST_BUTIL_SOURCES = \
version_unittest.cc \
logging_unittest.cc \
tuple_unittest.cc \
xdg_util_unittest.cc \
cacheline_unittest.cpp \
class_name_unittest.cpp \
endpoint_unittest.cpp \
Expand All @@ -124,11 +120,9 @@ TEST_BUTIL_SOURCES = \
flat_map_unittest.cpp \
crc32c_unittest.cc \
iobuf_unittest.cc \
multiprocess_func_list.cc \
test_switches.cc \
test_timeouts.cc \
scoped_locale.cc \
multiprocess_test.cc \
test_file_util.cc \
test_file_util_linux.cc \
butil_unittest_main.cpp
Expand Down
19 changes: 19 additions & 0 deletions test/sstream_workaround.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2017 Baidu, Inc.
// Author: Zhangyi Chen ([email protected])

#ifndef BUTIL_TEST_SSTREAM_WORKAROUND
#define BUTIL_TEST_SSTREAM_WORKAROUND

// defining private as public makes it fail to compile sstream with gcc5.x like this:
// "error: ‘struct std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>::
// __xfer_bufptrs’ redeclared with different access"

#ifdef private
# undef private
# include <sstream>
# define private public
#else
# include <sstream>
#endif

#endif // BUTIL_TEST_SSTREAM_WORKAROUND

0 comments on commit a6109be

Please sign in to comment.