Merge branch 'gcc8-msw-warns'

Fix tons of warnings given by default by gcc 8, potentially fixing some
real problems in Win64 build in the process.

See https://github.com/wxWidgets/wxWidgets/pull/822
This commit is contained in:
Vadim Zeitlin
2018-06-10 23:41:05 +02:00
18 changed files with 141 additions and 112 deletions

View File

@@ -667,6 +667,17 @@ typedef short int WXTYPE;
# define wxGCC_WARNING_RESTORE(x)
#endif
/* Specific macros for -Wcast-function-type warning new in gcc 8. */
#if wxCHECK_GCC_VERSION(8, 0)
#define wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE() \
wxGCC_WARNING_SUPPRESS(cast-function-type)
#define wxGCC_WARNING_RESTORE_CAST_FUNCTION_TYPE() \
wxGCC_WARNING_RESTORE(cast-function-type)
#else
#define wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE()
#define wxGCC_WARNING_RESTORE_CAST_FUNCTION_TYPE()
#endif
/*
Macros to suppress and restore clang warning only when it is valid.
@@ -2845,11 +2856,18 @@ typedef wxW64 long WXLPARAM;
typedef wxW64 long WXLRESULT;
#endif
/*
This is defined for compatibility only, it's not really the same thing as
FARPROC.
*/
#if defined(__GNUWIN32__)
typedef int (*WXFARPROC)();
#else
typedef int (__stdcall *WXFARPROC)();
#endif
typedef WXLRESULT (wxSTDCALL *WXWNDPROC)(WXHWND, WXUINT, WXWPARAM, WXLPARAM);
#endif /* __WIN32__ */

View File

@@ -44,6 +44,11 @@ typedef int (wxCMPFUNC_CONV *CMPFUNC)(const void* pItem1, const void* pItem2);
// Array class providing legacy dynamic arrays API on top of wxVector<>
// ----------------------------------------------------------------------------
// For some reasons lost in the depths of time, sort functions with different
// signatures are used to sort normal arrays and to keep sorted arrays sorted.
// These two functors can be used as predicates with std::sort() adapting the
// sort function to it, whichever signature it uses.
template<class T>
class wxArray_SortFunction
{
@@ -52,7 +57,7 @@ public:
wxArray_SortFunction(CMPFUNC f) : m_f(f) { }
bool operator()(const T& i1, const T& i2)
{ return m_f((T*)&i1, (T*)&i2) < 0; }
{ return m_f(const_cast<T*>(&i1), const_cast<T*>(&i2)) < 0; }
private:
CMPFUNC m_f;
};
@@ -74,9 +79,9 @@ template <typename T>
class wxBaseArray : public wxVector<T>
{
typedef wxSortedArray_SortFunction<T> Predicate;
typedef int (wxCMPFUNC_CONV *SCMPFUNC)(T, T);
public:
typedef typename Predicate::CMPFUNC SCMPFUNC;
typedef typename wxArray_SortFunction<T>::CMPFUNC CMPFUNC;
typedef wxVector<T> base_vec;
@@ -151,17 +156,17 @@ public:
return wxNOT_FOUND;
}
int Index(T lItem, CMPFUNC fnCompare) const
int Index(T lItem, SCMPFUNC fnCompare) const
{
Predicate p((SCMPFUNC)fnCompare);
Predicate p(fnCompare);
const_iterator i = std::lower_bound(this->begin(), this->end(), lItem, p);
return i != this->end() && !p(lItem, *i) ? (int)(i - this->begin())
: wxNOT_FOUND;
}
size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const
size_t IndexForInsert(T lItem, SCMPFUNC fnCompare) const
{
Predicate p((SCMPFUNC)fnCompare);
Predicate p(fnCompare);
const_iterator i = std::lower_bound(this->begin(), this->end(), lItem, p);
return i - this->begin();
}
@@ -171,7 +176,7 @@ public:
this->insert(this->end(), nInsert, lItem);
}
size_t Add(T lItem, CMPFUNC fnCompare)
size_t Add(T lItem, SCMPFUNC fnCompare)
{
size_t n = IndexForInsert(lItem, fnCompare);
Insert(lItem, n);
@@ -200,6 +205,12 @@ public:
wxArray_SortFunction<T> p(fCmp);
std::sort(this->begin(), this->end(), p);
}
void Sort(SCMPFUNC fCmp)
{
Predicate p(fCmp);
std::sort(this->begin(), this->end(), p);
}
};
// ============================================================================
@@ -223,8 +234,6 @@ public:
template <typename T, typename Cmp>
class wxBaseSortedArray : public wxBaseArray<T>
{
typedef typename wxBaseArray<T>::CMPFUNC CMPFUNC;
public:
explicit wxBaseSortedArray(Cmp fn) : m_fnCompare(fn) { }
@@ -237,7 +246,7 @@ public:
size_t IndexForInsert(T item) const
{
return this->wxBaseArray<T>::IndexForInsert(item, (CMPFUNC)m_fnCompare);
return this->wxBaseArray<T>::IndexForInsert(item, m_fnCompare);
}
void AddAt(T item, size_t index)
@@ -247,7 +256,7 @@ public:
size_t Add(T item)
{
return this->wxBaseArray<T>::Add(item, (CMPFUNC)m_fnCompare);
return this->wxBaseArray<T>::Add(item, m_fnCompare);
}
void push_back(T item)

View File

@@ -81,9 +81,9 @@ typedef int wxEventType;
#define wxEVT_ANY ((wxEventType)-1)
// this is used to make the event table entry type safe, so that for an event
// handler only a function with proper parameter list can be given. See also
// the wxEVENT_HANDLER_CAST-macro.
// This macro exists for compatibility only (even though it was never public,
// it still appears in some code using wxWidgets), see public
// wxEVENT_HANDLER_CAST instead.
#define wxStaticCastEvent(type, val) static_cast<type>(val)
#define wxDECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
@@ -122,10 +122,30 @@ extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
#define wxDECLARE_EXPORTED_EVENT_ALIAS( expdecl, name, type ) \
extern const expdecl wxEventTypeTag< type > name
// Try to cast the given event handler to the correct handler type:
// The type-erased method signature used for event handling.
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
template <typename T>
inline wxEventFunction wxEventFunctionCast(void (wxEvtHandler::*func)(T&))
{
// There is no going around the cast here: we do rely calling the event
// handler method, which takes a reference to an object of a class derived
// from wxEvent, as if it took wxEvent itself. On all platforms supported
// by wxWidgets, this cast is harmless, but it's not a valid cast in C++
// and gcc 8 started giving warnings about this (with -Wextra), so suppress
// them locally to avoid generating hundreds of them when compiling any
// code using event table macros.
wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE()
return reinterpret_cast<wxEventFunction>(func);
wxGCC_WARNING_RESTORE_CAST_FUNCTION_TYPE()
}
// Try to cast the given event handler to the correct handler type:
#define wxEVENT_HANDLER_CAST( functype, func ) \
( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
wxEventFunctionCast(static_cast<functype>(&func))
// The tag is a type associated to the event type (which is an integer itself,
@@ -150,9 +170,6 @@ private:
wxEventType m_type;
};
// These are needed for the functor definitions
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
// We had some trouble with using wxEventFunction
// in the past so we had introduced wxObjectEventFunction which
// used to be a typedef for a member of wxObject and not wxEvtHandler to work
@@ -295,8 +312,8 @@ struct HandlerImpl<T, A, true>
static wxEvtHandler *ConvertToEvtHandler(T *p)
{ return p; }
static wxEventFunction ConvertToEvtMethod(void (T::*f)(A&))
{ return static_cast<wxEventFunction>(
reinterpret_cast<void (T::*)(wxEvent&)>(f)); }
{ return wxEventFunctionCast(
static_cast<void (wxEvtHandler::*)(A&)>(f)); }
};
// specialization for handlers not deriving from wxEvtHandler

View File

@@ -81,7 +81,7 @@ class WXDLLIMPEXP_BASE _wxHashTableBase2
{
public:
typedef void (*NodeDtor)(_wxHashTable_NodeBase*);
typedef unsigned long (*BucketFromNode)(_wxHashTableBase2*,_wxHashTable_NodeBase*);
typedef size_t (*BucketFromNode)(_wxHashTableBase2*,_wxHashTable_NodeBase*);
typedef _wxHashTable_NodeBase* (*ProcessNode)(_wxHashTable_NodeBase*);
protected:
static _wxHashTable_NodeBase* DummyProcessNode(_wxHashTable_NodeBase* node);

View File

@@ -936,7 +936,10 @@ extern WXDLLIMPEXP_CORE int wxGetWindowId(WXHWND hWnd);
// check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
// different
extern WXDLLIMPEXP_CORE bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc);
//
// wndProc parameter is unused and only kept for compatibility
extern WXDLLIMPEXP_CORE
bool wxCheckWindowWndProc(WXHWND hWnd, WXWNDPROC wndProc = NULL);
// Does this window style specify any border?
inline bool wxStyleHasBorder(long style)
@@ -1055,54 +1058,28 @@ inline void wxFillRect(HWND hwnd, HDC hdc, HBRUSH hbr)
// 32/64 bit helpers
// ----------------------------------------------------------------------------
#ifdef __WIN64__
inline void *wxGetWindowProc(HWND hwnd)
{
return (void *)::GetWindowLongPtr(hwnd, GWLP_WNDPROC);
}
inline void *wxGetWindowUserData(HWND hwnd)
{
return (void *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
inline WNDPROC wxSetWindowProc(HWND hwnd, WNDPROC func)
{
return (WNDPROC)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)func);
}
inline void *wxSetWindowUserData(HWND hwnd, void *data)
{
return (void *)::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data);
}
#else // __WIN32__
// note that the casts to LONG_PTR here are required even on 32-bit machines
// for the 64-bit warning mode of later versions of MSVC (C4311/4312)
inline WNDPROC wxGetWindowProc(HWND hwnd)
{
return (WNDPROC)(LONG_PTR)::GetWindowLong(hwnd, GWL_WNDPROC);
return (WNDPROC)(LONG_PTR)::GetWindowLongPtr(hwnd, GWLP_WNDPROC);
}
inline void *wxGetWindowUserData(HWND hwnd)
{
return (void *)(LONG_PTR)::GetWindowLong(hwnd, GWL_USERDATA);
return (void *)(LONG_PTR)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
inline WNDPROC wxSetWindowProc(HWND hwnd, WNDPROC func)
{
return (WNDPROC)(LONG_PTR)::SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR)func);
return (WNDPROC)(LONG_PTR)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)func);
}
inline void *wxSetWindowUserData(HWND hwnd, void *data)
{
return (void *)(LONG_PTR)::SetWindowLong(hwnd, GWL_USERDATA, (LONG_PTR)data);
return (void *)(LONG_PTR)::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data);
}
#endif // __WIN64__/__WIN32__
#endif // wxUSE_GUI && __WXMSW__
#endif // _WX_PRIVATE_H_

View File

@@ -100,7 +100,7 @@ public:
// for internal use only
// get the subclassed window proc of the buddy text
WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; }
WXWNDPROC GetBuddyWndProc() const { return m_wndProcBuddy; }
// return the spinctrl object whose buddy is the given window or NULL
static wxSpinCtrl *GetSpinForTextCtrl(WXHWND hwndBuddy);
@@ -145,7 +145,7 @@ protected:
// the data for the "buddy" text ctrl
WXHWND m_hwndBuddy;
WXFARPROC m_wndProcBuddy;
WXWNDPROC m_wndProcBuddy;
// Block text update event after SetValue()
bool m_blockEvent;

View File

@@ -206,8 +206,8 @@ public:
void SubclassWin(WXHWND hWnd);
void UnsubclassWin();
WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
WXWNDPROC MSWGetOldWndProc() const { return m_oldWndProc; }
void MSWSetOldWndProc(WXWNDPROC proc) { m_oldWndProc = proc; }
// return true if the window is of a standard (i.e. not wxWidgets') class
//
@@ -597,7 +597,7 @@ protected:
WXHWND m_hWnd;
// the old window proc (we subclass all windows)
WXFARPROC m_oldWndProc;
WXWNDPROC m_oldWndProc;
// additional (MSW specific) flags
bool m_mouseInWindow:1;