Avoid strict aliasing warning on function pointers

Cast via an ordinary function pointer rather than a function pointer
reference to avoid the warning.

Also make the pointer in `Func_t` explicit rather than implicit (deduced
into the `Func_t` type) to make it clearer what is going on here.
pull/1969/head
Jason Rhinelander 2 years ago
parent ef4e720890
commit 58eec9ed11
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -14,12 +14,12 @@ namespace llarp::win32
/// throws if the function does not exist in the DLL we openned.
template <typename Func_t>
void
init(std::string name, Func_t& func)
init(std::string name, Func_t*& func)
{
auto ptr = GetProcAddress(m_Handle, name.c_str());
if (not ptr)
throw win32::error{fmt::format("function '{}' not found", name)};
func = reinterpret_cast<Func_t&>(ptr);
func = reinterpret_cast<Func_t*>(ptr);
}
public:

Loading…
Cancel
Save