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 <typename Logger> 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.
This commit is contained in:
木头云 2025-12-15 12:10:26 +00:00
parent 72eedeb6c4
commit ab8e6c7d2c

View File

@ -5,16 +5,13 @@
namespace ipc { namespace ipc {
namespace detail { namespace detail {
inline LPSECURITY_ATTRIBUTES get_sa() { struct sa_initiator {
LIBIPC_LOG();
struct initiator {
SECURITY_DESCRIPTOR sd_; SECURITY_DESCRIPTOR sd_;
SECURITY_ATTRIBUTES sa_; SECURITY_ATTRIBUTES sa_;
bool succ_ = false; bool succ_ = false;
template <typename Logger> template <typename Logger>
initiator(Logger const &log) { sa_initiator(Logger const &log) {
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) { if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]"); log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
return; return;
@ -30,7 +27,9 @@ inline LPSECURITY_ATTRIBUTES get_sa() {
} }
}; };
static initiator handle(log); inline LPSECURITY_ATTRIBUTES get_sa() {
LIBIPC_LOG();
static sa_initiator handle(log);
return handle.succ_ ? &handle.sa_ : nullptr; return handle.succ_ ? &handle.sa_ : nullptr;
} }