Work around gcc 8 -Wcast-function-type in wxMSW wxGLContext

Casts between incompatible function types seem to be unavoidable here,
as wglGetProcAddress() always returns generic PROC type, so just
suppress the warnings temporarily.
This commit is contained in:
Vadim Zeitlin
2018-05-29 13:48:14 +02:00
parent ed01fede2e
commit 1abdac6566

View File

@@ -147,8 +147,24 @@ wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
#define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
#endif
typedef HGLRC(WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)
(HDC hDC, HGLRC hShareContext, const int *attribList);
// This helper function only exists to suppress unavoidable gcc 8 warnings
// about incompatible function casts.
template <typename T>
inline T wxWGLProcCast(PROC proc)
{
wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE()
return reinterpret_cast<T>(proc);
wxGCC_WARNING_RESTORE_CAST_FUNCTION_TYPE()
}
// this macro defines a variable of type "name_t" called "name" and initializes
// it with the pointer to WGL function "name" (which may be NULL)
//
// NB: type name_t must be defined by the code using the macro
#define wxDEFINE_WGL_FUNC(name) \
name##_t name = wxWGLProcCast<name##_t>(wglGetProcAddress(#name))
// ----------------------------------------------------------------------------
// libraries
@@ -580,9 +596,11 @@ wxGLContext::wxGLContext(wxGLCanvas *win,
wxCHECK_RET( tempContext, "wglCreateContext failed!" );
wglMakeCurrent(win->GetHDC(), tempContext);
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB
= (PFNWGLCREATECONTEXTATTRIBSARBPROC)
wglGetProcAddress("wglCreateContextAttribsARB");
typedef HGLRC(WINAPI * wglCreateContextAttribsARB_t)
(HDC hDC, HGLRC hShareContext, const int *attribList);
wxDEFINE_WGL_FUNC(wglCreateContextAttribsARB);
wglMakeCurrent(win->GetHDC(), NULL);
wglDeleteContext(tempContext);
@@ -810,11 +828,6 @@ bool wxGLCanvas::SwapBuffers()
}
// this macro defines a variable of type "name_t" called "name" and initializes
// it with the pointer to WGL function "name" (which may be NULL)
#define wxDEFINE_WGL_FUNC(name) \
name##_t name = (name##_t)wglGetProcAddress(#name)
/* static */
bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
{