Description
When building BRPC tests with C++17 (GCC 12+), compilation fails with:
error: 'struct std::any::_Manager_internal<_Tp>' redeclared with different access
The root cause is -Dprivate=public -Dprotected=public in test/CMakeLists.txt line 56, which is used to access private members in tests. This macro rewrites private to public in all headers, including standard library headers like <any>.
Steps to Reproduce
# On GCC 12+ with C++17
g++ -std=c++17 -Dprivate=public -Dprotected=public -c test.cpp
# where test.cpp transitively includes <any> (e.g. via gtest-port.h)
The <any> header is pulled in by gtest's gtest-port.h:2312:
#if __has_include(<any>) && __cplusplus >= 201703L
#include <any>
#endif
Environment
- GCC 12+ (tested with GCC 13.3 on x86, GCC 15.1 on RISC-V)
- C++17 or later
- Any architecture (x86, ARM, RISC-V)
Root Cause
test/CMakeLists.txt line 56:
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ... -Dprivate=public -Dprotected=public -include ${PROJECT_SOURCE_DIR}/test/sstream_workaround.h")
The existing sstream_workaround.h handles the same issue for <sstream> by including it before the macro takes effect, but does not protect <any>.
Why CI Does Not Catch This
BRPC's CMakeLists.txt hardcodes -std=c++11 (line 155/158), so __cplusplus is 201103L and gtest skips the #include <any>. The bug only manifests when building with C++17 explicitly or when the compiler defaults to C++17 (e.g. GCC 14+).
Description
When building BRPC tests with C++17 (GCC 12+), compilation fails with:
The root cause is
-Dprivate=public -Dprotected=publicintest/CMakeLists.txtline 56, which is used to access private members in tests. This macro rewritesprivatetopublicin all headers, including standard library headers like<any>.Steps to Reproduce
The
<any>header is pulled in by gtest'sgtest-port.h:2312:Environment
Root Cause
test/CMakeLists.txtline 56:The existing
sstream_workaround.hhandles the same issue for<sstream>by including it before the macro takes effect, but does not protect<any>.Why CI Does Not Catch This
BRPC's CMakeLists.txt hardcodes
-std=c++11(line 155/158), so__cplusplusis201103Land gtest skips the#include <any>. The bug only manifests when building with C++17 explicitly or when the compiler defaults to C++17 (e.g. GCC 14+).