fix(log): use constructor template instead of class template for initiator

- src/libipc/platform/win/get_sa.h:
  * Change from class template to constructor template
  * Keep 'struct initiator' as a regular class (not template)
  * Make constructor a function template: template <typename Logger> initiator(Logger const &log)
  * Instantiate as: static initiator handle(log);
  * This is valid C++ as function templates can be defined inside functions
  * Fixes the issue that class templates cannot be defined inside functions

The constructor template approach allows proper logger passing while
maintaining valid C++ syntax for local struct definitions.
This commit is contained in:
木头云 2025-12-15 11:58:13 +00:00
parent afd1467e03
commit 72eedeb6c4

View File

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