From ab8e6c7d2c979d070dadee75199a5db2d9b17681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=A4=B4=E4=BA=91?= <372449116@qq.com> Date: Mon, 15 Dec 2025 12:10:26 +0000 Subject: [PATCH] fix(log): move sa_initiator struct outside get_sa() function - src/libipc/platform/win/get_sa.h: * Move 'struct initiator' definition outside get_sa() function * Rename to 'sa_initiator' to avoid naming conflicts * Define at namespace ipc::detail scope (above get_sa function) * Keep template constructor: template sa_initiator(Logger const &log) * get_sa() now simply uses: static sa_initiator handle(log); This fixes the C++ standard violation: - C++03/11/14/17/20 all prohibit local classes from having member templates - Error C2892: 'local class shall not have member templates' - Moving the struct to namespace scope resolves this issue The struct is now a proper namespace-level definition with a template constructor, which is fully compliant with C++ standards. --- src/libipc/platform/win/get_sa.h | 47 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/libipc/platform/win/get_sa.h b/src/libipc/platform/win/get_sa.h index 30295db..a81eed2 100644 --- a/src/libipc/platform/win/get_sa.h +++ b/src/libipc/platform/win/get_sa.h @@ -5,32 +5,31 @@ namespace ipc { namespace detail { +struct sa_initiator { + SECURITY_DESCRIPTOR sd_; + SECURITY_ATTRIBUTES sa_; + bool succ_ = false; + + template + sa_initiator(Logger const &log) { + if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) { + log.error("fail InitializeSecurityDescriptor[", static_cast(::GetLastError()), "]"); + return; + } + if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) { + log.error("fail SetSecurityDescriptorDacl[", static_cast(::GetLastError()), "]"); + return; + } + sa_.nLength = sizeof(SECURITY_ATTRIBUTES); + sa_.bInheritHandle = FALSE; + sa_.lpSecurityDescriptor = &sd_; + succ_ = true; + } +}; + inline LPSECURITY_ATTRIBUTES get_sa() { LIBIPC_LOG(); - - struct initiator { - SECURITY_DESCRIPTOR sd_; - SECURITY_ATTRIBUTES sa_; - bool succ_ = false; - - template - initiator(Logger const &log) { - if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) { - log.error("fail InitializeSecurityDescriptor[", static_cast(::GetLastError()), "]"); - return; - } - if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) { - log.error("fail SetSecurityDescriptorDacl[", static_cast(::GetLastError()), "]"); - return; - } - sa_.nLength = sizeof(SECURITY_ATTRIBUTES); - sa_.bInheritHandle = FALSE; - sa_.lpSecurityDescriptor = &sd_; - succ_ = true; - } - }; - - static initiator handle(log); + static sa_initiator handle(log); return handle.succ_ ? &handle.sa_ : nullptr; }