From 39380847da0b3989741667c53d9c251b58288b7b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Mar 2019 15:12:58 +0100 Subject: [PATCH] Avoid redundant declarations for wxQsort() This works around gcc -Wredundant-decls warning that was given (if explicitly enabled) when both wx/vector.h and wx/utils.h were included. The workaround is ugly, but it doesn't seem worth it to introduce a separate wx/qsort.h header just for this single function, which seems to be the only other way to fix this. Closes https://github.com/wxWidgets/wxWidgets/pull/1271 --- include/wx/utils.h | 7 +++++++ include/wx/vector.h | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/include/wx/utils.h b/include/wx/utils.h index 7cf8399f18..037bb88582 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -603,6 +603,11 @@ WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path, +// See wx/vector.h for more about this hack. +#ifndef wxQSORT_DECLARED + +#define wxQSORT_DECLARED + typedef int (*wxSortCallback)(const void* pItem1, const void* pItem2, const void* user_data); @@ -612,6 +617,8 @@ WXDLLIMPEXP_BASE void wxQsort(void* pbase, size_t total_elems, size_t size, wxSortCallback cmp, const void* user_data); +#endif // !wxQSORT_DECLARED + #if wxUSE_GUI // GUI only things from now on diff --git a/include/wx/vector.h b/include/wx/vector.h index 25067081b4..c15d1630a6 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -41,6 +41,13 @@ inline void wxVectorSort(wxVector& v) // wxQsort is declared in wx/utils.h, but can't include that file here, // it indirectly includes this file. Just lovely... +// +// Moreover, just declaring it here unconditionally results in gcc +// -Wredundant-decls warning, so use a preprocessor guard to avoid this. +#ifndef wxQSORT_DECLARED + +#define wxQSORT_DECLARED + typedef int (*wxSortCallback)(const void* pItem1, const void* pItem2, const void* user_data); @@ -48,6 +55,8 @@ WXDLLIMPEXP_BASE void wxQsort(void* pbase, size_t total_elems, size_t size, wxSortCallback cmp, const void* user_data); +#endif // !wxQSORT_DECLARED + namespace wxPrivate {