Skip to content

Commit ab8e6c7

Browse files
committed
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.
1 parent 72eedeb commit ab8e6c7

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/libipc/platform/win/get_sa.h

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,31 @@
55
namespace ipc {
66
namespace detail {
77

8-
inline LPSECURITY_ATTRIBUTES get_sa() {
9-
LIBIPC_LOG();
10-
11-
struct initiator {
12-
SECURITY_DESCRIPTOR sd_;
13-
SECURITY_ATTRIBUTES sa_;
14-
bool succ_ = false;
8+
struct sa_initiator {
9+
SECURITY_DESCRIPTOR sd_;
10+
SECURITY_ATTRIBUTES sa_;
11+
bool succ_ = false;
1512

16-
template <typename Logger>
17-
initiator(Logger const &log) {
18-
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
19-
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
20-
return;
21-
}
22-
if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) {
23-
log.error("fail SetSecurityDescriptorDacl[", static_cast<int>(::GetLastError()), "]");
24-
return;
25-
}
26-
sa_.nLength = sizeof(SECURITY_ATTRIBUTES);
27-
sa_.bInheritHandle = FALSE;
28-
sa_.lpSecurityDescriptor = &sd_;
29-
succ_ = true;
13+
template <typename Logger>
14+
sa_initiator(Logger const &log) {
15+
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
16+
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
17+
return;
18+
}
19+
if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) {
20+
log.error("fail SetSecurityDescriptorDacl[", static_cast<int>(::GetLastError()), "]");
21+
return;
3022
}
31-
};
32-
33-
static initiator handle(log);
23+
sa_.nLength = sizeof(SECURITY_ATTRIBUTES);
24+
sa_.bInheritHandle = FALSE;
25+
sa_.lpSecurityDescriptor = &sd_;
26+
succ_ = true;
27+
}
28+
};
29+
30+
inline LPSECURITY_ATTRIBUTES get_sa() {
31+
LIBIPC_LOG();
32+
static sa_initiator handle(log);
3433
return handle.succ_ ? &handle.sa_ : nullptr;
3534
}
3635

0 commit comments

Comments
 (0)