summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Lesin <vlad_lesin@mail.ru>2019-11-15 15:15:10 +0300
committerVlad Lesin <vlad_lesin@mail.ru>2019-11-15 15:15:10 +0300
commit922a8534df1d4fb93878baba9eda321af9048b63 (patch)
tree4297b560e9b51a643a13b557139b281c26a8fc0d
parentbd2b05df6c5806e599698eb239b3e44b971eb031 (diff)
downloadmariadb-git-bb-10.2-MDEV-21050-isfinite-isnan-isinf.tar.gz
MDEV-21050: warning: 'finite' is deprecated: first deprecated in macOSbb-10.2-MDEV-21050-isfinite-isnan-isinf
10.9 The issue is not only in is_finite() deprecation. On some platforms(like Ubuntu 16.04) math.h contains isnan/isinf definition only for C99 standard. If some code is compiled with C++11 standard, math.h does not contain isnan/isinf definitions, it's supposed cmath must be used instead of math.h for C++11. At the other hand, CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN) returns true because it uses try_compile() cmake function, which does not apply CMAKE_CXX_FLAGS or CMAKE_CXX_STANDARD in cmake <= 3.7(default cmake version for Ubuntu 16.04 is 3.5), and the code, passed as an argument to try_compile(), is compiled under default C99 standard(if the correspondent compilation flag is not set explicitly in CMAKE_REQUIRED_FLAGS). So on Ubuntu 16.04 we have HAVE_ISNAN/HAVE_ISINF set to true, but isnan/isinf are not defined in math.h if the code is compiled under C++11 standard, what is true for ES and 10.4+ CS. To avoid this, we use std::isnan/std::isinf if the code is compiled with C++11 standard. To use std::isnan/std::isinf we must include cmath. It was included in my_global.h only if "isfinite" macro is not defined and C++11 is used. But there is another issue. On some platforms like MacOS X, "isfinite" is defined for both C99 and C++11 standards, so on MacOS X cmath was not included in my_global.h, what caused compilation errors for the code which used std::inan/std::isinf. Besides "isfinite" is deprecated since MacOS 10.9, what led to a lot of warnins during compilation. That is why we include cmath and use std::isfinite on C++11 standard, even if "isfinite" is defined. Besides, C++11 standard contains the following information(C++11 17.6.1.2/4): In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (7.3.3). So <cmath> can contain isfinite() declaration, that is why macro definition for "isfinit" is used instead of inline function declaration.
-rw-r--r--include/my_global.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/include/my_global.h b/include/my_global.h
index 4ce4671c571..62aba20b26f 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -811,27 +811,35 @@ inline unsigned long long my_double2ulonglong(double d)
#define SIZE_T_MAX (~((size_t) 0))
#endif
-#ifndef isfinite
+#if (__cplusplus >= 201103L)
+#include <cmath>
+#define isfinite(x) std::isfinite(x)
+#elif !defined(isfinite) /* (__cplusplus >= 201103L) */
#ifdef HAVE_FINITE
#define isfinite(x) finite(x)
#else
#define finite(x) (1.0 / fabs(x) > 0.0)
#endif /* HAVE_FINITE */
-#elif (__cplusplus >= 201103L)
-#include <cmath>
-static inline bool isfinite(double x) { return std::isfinite(x); }
-#endif /* isfinite */
+#endif /* !defined(isfinite) */
+#if (__cplusplus >= 201103L)
+#define my_isnan(x) std::isnan(x)
+#else /* (__cplusplus >= 201103L) */
#ifndef HAVE_ISNAN
#define isnan(x) ((x) != (x))
#endif
#define my_isnan(x) isnan(x)
+#endif /* (__cplusplus >= 201103L) */
+#if (__cplusplus >= 201103L)
+#define my_isinf(x) std::isinf(x)
+#else /* (__cplusplus >= 201103L) */
#ifdef HAVE_ISINF
#define my_isinf(X) isinf(X)
#else /* !HAVE_ISINF */
#define my_isinf(X) (!finite(X) && !isnan(X))
-#endif
+#endif /* !HAVE_ISINF */
+#endif /* (__cplusplus >= 201103L) */
/* Define missing math constants. */
#ifndef M_PI