Silence gcc-8 -Wcast-function-type in except.cpp

gcc-8 adds a new warning controlled by -Wcast-function-type, which is
implied on by Rebirth's default options.  This new warning rejects
attempts to reinterpret_cast between function pointer types.  While this
might provide some value when the function pointer was derived by taking
the address of a properly declared function provided elsewhere in the
same program, it is wrong when the function pointer is returned by an
external library call, such as GetProcAddress, which always returns a
placeholder type instead of the actual type of the target function.
Switch to using a union with type-punning, which achieves the same
effect as the cast, but does not count as a cast, and therefore does not
provoke the warning.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/388>
This commit is contained in:
Kp 2018-07-15 04:43:55 +00:00
parent 20f1934312
commit fd0238cb6b

View file

@ -79,7 +79,12 @@ public:
template <typename T>
T *GetProc(const char *const proc) const
{
return reinterpret_cast<T *>(GetProcAddress(m_h, proc));
union {
FARPROC gpa;
T *result;
};
gpa = GetProcAddress(m_h, proc);
return result;
}
};