From fd0238cb6ba0c6e1b55dd905748474e1f0f77661 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 15 Jul 2018 04:43:55 +0000 Subject: [PATCH] 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: --- common/arch/win32/except.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/arch/win32/except.cpp b/common/arch/win32/except.cpp index 57f75f058..29782dea6 100644 --- a/common/arch/win32/except.cpp +++ b/common/arch/win32/except.cpp @@ -79,7 +79,12 @@ public: template T *GetProc(const char *const proc) const { - return reinterpret_cast(GetProcAddress(m_h, proc)); + union { + FARPROC gpa; + T *result; + }; + gpa = GetProcAddress(m_h, proc); + return result; } };