Skip to content

Commit 11c8ea9

Browse files
authored
Use -fno-access-control instead of -Dprivate=public for tests (#3346)
Replace the -Dprivate=public/-Dprotected=public macro hack with -fno-access-control compiler flag in test builds. This avoids redeclaration issues with standard library headers (e.g. <any> under C++17) while still allowing tests to access private members. Changes: - test/CMakeLists.txt: replace -Dprivate=public with -fno-access-control - test/Makefile: replace -Dprivate=public with -fno-access-control - test/BUILD.bazel: remove sstream_workaround cc_library and all deps - test/sstream_workaround.h: remove workaround (no longer needed)
1 parent f04e0e0 commit 11c8ea9

4 files changed

Lines changed: 4 additions & 48 deletions

File tree

test/BUILD.bazel

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ brpc_proto_library(
143143
visibility = ["//visibility:public"],
144144
)
145145

146-
cc_library(
147-
name = "sstream_workaround",
148-
hdrs = [
149-
"sstream_workaround.h",
150-
],
151-
)
152-
153146
cc_library(
154147
name = "gperftools_helper",
155148
hdrs = [
@@ -182,7 +175,6 @@ cc_test(
182175
defines = ["HAS_NLOHMANN_JSON=1"],
183176
deps = [
184177
":cc_test_proto",
185-
":sstream_workaround",
186178
":gperftools_helper",
187179
"//:butil",
188180
"//:bthread",
@@ -195,7 +187,6 @@ cc_test(
195187
name = "bvar_unittests",
196188
srcs = glob(["bvar_*_unittest.cpp"]),
197189
deps = [
198-
":sstream_workaround",
199190
":gperftools_helper",
200191
"//:bvar",
201192
"@com_google_googletest//:gtest",
@@ -210,7 +201,6 @@ generate_unittests(
210201
"bthread*_unittest.cpp",
211202
]),
212203
deps = [
213-
":sstream_workaround",
214204
":gperftools_helper",
215205
"//:bthread",
216206
"@com_google_googletest//:gtest",
@@ -239,7 +229,6 @@ generate_unittests(
239229
"brpc_*_unittest.cpp",
240230
]),
241231
deps = [
242-
":sstream_workaround",
243232
":gperftools_helper",
244233
"//:brpc",
245234
":cc_test_proto",

test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ else()
5353
endif()
5454

5555
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL}")
56-
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__=__unused__ -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES -D__STRICT_ANSI__ -include ${PROJECT_SOURCE_DIR}/test/sstream_workaround.h")
57-
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer")
56+
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__=__unused__ -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -DBVAR_NOT_LINK_DEFAULT_VARIABLES -D__STRICT_ANSI__")
57+
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -fno-access-control")
5858
use_cxx11()
5959

6060
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

test/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
NEED_GPERFTOOLS=1
1919
NEED_GTEST=1
2020
include ../config.mk
21-
CPPFLAGS+=-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES --include sstream_workaround.h
22-
CXXFLAGS+=$(CPPFLAGS) -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -std=c++0x
21+
CPPFLAGS+=-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -DBVAR_NOT_LINK_DEFAULT_VARIABLES
22+
CXXFLAGS+=$(CPPFLAGS) -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -fno-access-control -std=c++0x
2323

2424
# On Darwin, only gtest library is needed, other libraries have been linked in `brpc.dbg.dylib`
2525
ifeq ($(SYSTEM),Darwin)

test/sstream_workaround.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)