From 2182a2eaa2c58291737dbe5fb9418525bb81fe95 Mon Sep 17 00:00:00 2001 From: panyfx <8242454+panyfx@user.noreply.gitee.com> Date: Tue, 6 Oct 2026 09:48:49 +0800 Subject: [PATCH 1/2] Fix GCC 16 compile Error: 1.The -D__STRICT_ANSI__ in CMakeLists.txt conflicts with libstdc++ 16's __int128 specialization 2. H2StreamContext is incomplete, so sizeof throws an error, causing unique_ptr to fail --- CMakeLists.txt | 14 +++++++++++++- src/brpc/policy/http2_rpc_protocol.cpp | 16 ++++++++++++++++ src/brpc/policy/http2_rpc_protocol.h | 16 ++-------------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9e1aa8fc3..cb3398b435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,9 +191,21 @@ list(APPEND BRPC_COMMON_DEFINITIONS __STDC_FORMAT_MACROS __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS - __STRICT_ANSI__ ) +# __STRICT_ANSI__ hides GNU extensions, but it conflicts with the __int128 +# specializations added in libstdc++ 16 (GCC 16), causing "redefinition of +# numeric_limits<__int128>". Probe support at configure time and only define +# it when it does not break compilation. +include(CheckCXXSourceCompiles) +set(CMAKE_REQUIRED_DEFINITIONS "-D__STRICT_ANSI__") +check_cxx_source_compiles("#include \nint main() { return 0; }" + BRPC_STRICT_ANSI_COMPILES) +unset(CMAKE_REQUIRED_DEFINITIONS) +if(BRPC_STRICT_ANSI_COMPILES) + list(APPEND BRPC_COMMON_DEFINITIONS __STRICT_ANSI__) +endif() + if(WITH_ASAN) list(APPEND BRPC_COMMON_COMPILE_OPTIONS -fsanitize=address) list(APPEND BRPC_COMMON_LINK_OPTIONS -fsanitize=address) diff --git a/src/brpc/policy/http2_rpc_protocol.cpp b/src/brpc/policy/http2_rpc_protocol.cpp index 6d9b2b8714..060b25faf1 100644 --- a/src/brpc/policy/http2_rpc_protocol.cpp +++ b/src/brpc/policy/http2_rpc_protocol.cpp @@ -1683,6 +1683,22 @@ bool H2Context::FlushPendingData(int stream_id) { return out.empty() || WriteAck(_socket, &out) == 0; } +H2UnsentRequest::H2UnsentRequest(Controller* c) + : _nref(1) + , _size(0) + , _stream_id(0) + , _cntl(c) { +#ifndef NDEBUG + get_h2_bvars()->h2_unsent_request_count << 1; +#endif +} + +H2UnsentRequest::~H2UnsentRequest() { +#ifndef NDEBUG + get_h2_bvars()->h2_unsent_request_count << -1; +#endif +} + H2UnsentRequest* H2UnsentRequest::New(Controller* c) { const HttpHeader& h = c->http_request(); const CommonStrings* const common = get_common_strings(); diff --git a/src/brpc/policy/http2_rpc_protocol.h b/src/brpc/policy/http2_rpc_protocol.h index 64c9864d68..b82dd93f55 100644 --- a/src/brpc/policy/http2_rpc_protocol.h +++ b/src/brpc/policy/http2_rpc_protocol.h @@ -165,20 +165,8 @@ friend void PackH2Request(butil::IOBuf*, SocketMessage**, void push(const std::string& name, const std::string& value) { new (&_list[_size++]) HPacker::Header(name, value); } - H2UnsentRequest(Controller* c) - : _nref(1) - , _size(0) - , _stream_id(0) - , _cntl(c) { -#ifndef NDEBUG - get_h2_bvars()->h2_unsent_request_count << 1; -#endif - } - ~H2UnsentRequest() { -#ifndef NDEBUG - get_h2_bvars()->h2_unsent_request_count << -1; -#endif - } + H2UnsentRequest(Controller* c); + ~H2UnsentRequest(); H2UnsentRequest(const H2UnsentRequest&); void operator=(const H2UnsentRequest&); void Destroy(); From c2170d4eb38f7fc4b36cf564c44e2a0eacb18f24 Mon Sep 17 00:00:00 2001 From: pynj2026 <159674473+pynj2026@users.noreply.github.com> Date: Tue, 6 Oct 2026 14:33:27 +0800 Subject: [PATCH 2/2] Fix GCC 16 compile Error: 1. Remove __STRICT_ANSI__ definition instead of probing it --- CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb3398b435..e98e0c4fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,19 +193,6 @@ list(APPEND BRPC_COMMON_DEFINITIONS __STDC_CONSTANT_MACROS ) -# __STRICT_ANSI__ hides GNU extensions, but it conflicts with the __int128 -# specializations added in libstdc++ 16 (GCC 16), causing "redefinition of -# numeric_limits<__int128>". Probe support at configure time and only define -# it when it does not break compilation. -include(CheckCXXSourceCompiles) -set(CMAKE_REQUIRED_DEFINITIONS "-D__STRICT_ANSI__") -check_cxx_source_compiles("#include \nint main() { return 0; }" - BRPC_STRICT_ANSI_COMPILES) -unset(CMAKE_REQUIRED_DEFINITIONS) -if(BRPC_STRICT_ANSI_COMPILES) - list(APPEND BRPC_COMMON_DEFINITIONS __STRICT_ANSI__) -endif() - if(WITH_ASAN) list(APPEND BRPC_COMMON_COMPILE_OPTIONS -fsanitize=address) list(APPEND BRPC_COMMON_LINK_OPTIONS -fsanitize=address)