From 5e2589920e50efc37a424bc9838a5411b36e7500 Mon Sep 17 00:00:00 2001 From: "yin.li" Date: Thu, 25 Dec 2025 21:46:04 +0800 Subject: [PATCH] Fix compile issue when the linking project is using C++23 The root cause is unique_ptr has constexpr destructor since C++23 libcxx/include/__memory/unique_ptr.h:75:19: error: invalid application of 'sizeof' to an incomplete type 'brpc::RedisCommandHandler' 75 | static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type"); | ^~~~~~~~~~~ libcxx/include/__memory/unique_ptr.h:290:7: note: in instantiation of member function 'std::default_delete::operator()' requested here 290 | __deleter_(__tmp); | ^ libcxx/include/__memory/unique_ptr.h:259:71: note: in instantiation of member function 'std::unique_ptr::reset' requested here 259 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); } | ^ src/brpc/redis.h:220:14: note: in instantiation of member function 'std::unique_ptr::~unique_ptr' requested here 220 | explicit RedisConnContext(const RedisService* rs) | ^ src/brpc/redis.h:190:7: note: forward declaration of 'brpc::RedisCommandHandler' 190 | class RedisCommandHandler; --- src/brpc/redis.cpp | 13 +++++++++---- src/brpc/redis.h | 5 +---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/brpc/redis.cpp b/src/brpc/redis.cpp index 9af036f857..b9c5363f3e 100644 --- a/src/brpc/redis.cpp +++ b/src/brpc/redis.cpp @@ -101,10 +101,10 @@ bool RedisRequest::AddCommand(const butil::StringPiece& command) { CHECK(st.ok()) << st; _has_error = true; return false; - } + } } -bool RedisRequest::AddCommandByComponents(const butil::StringPiece* components, +bool RedisRequest::AddCommandByComponents(const butil::StringPiece* components, size_t n) { if (_has_error) { return false; @@ -117,7 +117,7 @@ bool RedisRequest::AddCommandByComponents(const butil::StringPiece* components, CHECK(st.ok()) << st; _has_error = true; return false; - } + } } bool RedisRequest::AddCommandWithArgs(const char* fmt, ...) { @@ -356,7 +356,7 @@ bool RedisService::AddCommandHandler(const std::string& name, RedisCommandHandle _command_map[lcname] = handler; return true; } - + RedisCommandHandler* RedisService::FindCommandHandler(const butil::StringPiece& name) const { auto it = _command_map.find(name.as_string()); if (it != _command_map.end()) { @@ -371,6 +371,11 @@ RedisCommandHandler* RedisCommandHandler::NewTransactionHandler() { } // ========== impl of RedisConnContext ========== +RedisConnContext::RedisConnContext(const RedisService* rs) + : redis_service(rs) + , batched_size(0) + , session(nullptr) {} + RedisConnContext::~RedisConnContext() { } void RedisConnContext::Destroy() { diff --git a/src/brpc/redis.h b/src/brpc/redis.h index 50064519f7..c140baf34b 100644 --- a/src/brpc/redis.h +++ b/src/brpc/redis.h @@ -217,10 +217,7 @@ class RedisCommandParser; // This class is as parsing_context in socket. class RedisConnContext : public Destroyable { public: - explicit RedisConnContext(const RedisService* rs) - : redis_service(rs) - , batched_size(0) - , session(nullptr) {} + explicit RedisConnContext(const RedisService* rs); ~RedisConnContext(); // @Destroyable