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.
This commit is contained in:
Jason Rhinelander 2022-09-10 14:27:31 -03:00
parent ef4e720890
commit 58eec9ed11
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
1 changed files with 2 additions and 2 deletions

View File

@ -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: