From 33f9dbda891b14ea52c7526eede0cce422ce7c4c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 28 Dec 2012 00:44:01 +0000 Subject: [PATCH] Add wxGCC_WARNING_{SUPPRESS,RESTORE} macros and use them for -Wfloat-equal. Suppress the warnings about comparing floating point values for equality in wxWidgets headers when the user code is compiled with -Wfloat-equal (at least when using g++ 4.6 or later). Closes #14895. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73280 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/any.h | 4 ++++ include/wx/defs.h | 21 +++++++++++++++++++++ include/wx/math.h | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/wx/any.h b/include/wx/any.h index 6e38772532..2651ce219c 100644 --- a/include/wx/any.h +++ b/include/wx/any.h @@ -912,6 +912,8 @@ public: WXANY_IMPLEMENT_INT_EQ_OP(wxLongLong_t, wxULongLong_t) #endif + wxGCC_WARNING_SUPPRESS(float-equal) + bool operator==(float value) const { if ( !wxAnyValueTypeImpl::IsSameClass(m_type) ) @@ -932,6 +934,8 @@ public: (wxAnyValueTypeImpl::GetValue(m_buffer)); } + wxGCC_WARNING_RESTORE(float-equal) + bool operator==(bool value) const { if ( !wxAnyValueTypeImpl::IsSameClass(m_type) ) diff --git a/include/wx/defs.h b/include/wx/defs.h index a96a6e91f4..3e87cac57c 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -583,6 +583,27 @@ typedef short int WXTYPE; # define wxDEPRECATED_BUT_USED_INTERNALLY(x) wxDEPRECATED(x) #endif +/* + Macros to suppress and restore gcc warnings, requires g++ >= 4.6 and don't + do anything otherwise. + + Example of use: + + wxGCC_WARNING_SUPPRESS(float-equal) + inline bool wxIsSameDouble(double x, double y) { return x == y; } + wxGCC_WARNING_RESTORE(float-equal) + */ +#if wxCHECK_GCC_VERSION(4, 6) +# define wxGCC_WARNING_SUPPRESS(x) \ + _Pragma (wxSTRINGIZE(GCC diagnostic push)) \ + _Pragma (wxSTRINGIZE(GCC diagnostic ignored wxSTRINGIZE(wxCONCAT(-W,x)))) +# define wxGCC_WARNING_RESTORE(x) \ + _Pragma (wxSTRINGIZE(GCC diagnostic pop)) +#else /* gcc < 4.6 or not gcc at all */ +# define wxGCC_WARNING_SUPPRESS(x) +# define wxGCC_WARNING_RESTORE(x) +#endif + /* Combination of the two variants above: should be used for deprecated functions which are defined inline and are used by wxWidgets itself. diff --git a/include/wx/math.h b/include/wx/math.h index 98477e604e..5240f1759e 100644 --- a/include/wx/math.h +++ b/include/wx/math.h @@ -107,8 +107,9 @@ } #else /* !__INTELC__ */ - + wxGCC_WARNING_SUPPRESS(float-equal) inline bool wxIsSameDouble(double x, double y) { return x == y; } + wxGCC_WARNING_RESTORE(float-equal) #endif /* __INTELC__/!__INTELC__ */ -- 2.45.2