Felix-Gong opened a new issue, #3345:
URL: https://github.com/apache/brpc/issues/3345
## 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
```bash
# 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`:
```cpp
#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:
```cmake
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+).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]