Skip to content

Commit bc7320d

Browse files
committed
Backport from mysql-trunk to mysql-5.6 of:
------------------------------------------------------------ revno: 7033 committer: Jon Olav Hauglid <[email protected]> branch nick: mysql-trunk-c11 timestamp: Wed 2013-11-27 13:54:59 +0100 message: Bug#14631159: ALLOW COMPILATION USING CLANG IN C++11 MODE This patch fixes the new compilation errors that are reported by Clang and GCC when compiling in C++11 mode. The patch is not based on the contribution in the bug report.
1 parent 2b5d3d9 commit bc7320d

27 files changed

Lines changed: 85 additions & 99 deletions

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ IF(WITH_UNIT_TESTS)
470470
IF(WIN32)
471471
ADD_DEFINITIONS( /D _VARIADIC_MAX=10 )
472472
ENDIF()
473+
# libc++ doesn't have tuple in tr1
474+
IF(HAVE_LLVM_LIBCPP)
475+
ADD_DEFINITIONS(-DGTEST_USE_OWN_TR1_TUPLE=1)
476+
ENDIF()
473477
ADD_SUBDIRECTORY(unittest/gunit)
474478
ENDIF()
475479

cmake/os/WindowsCache.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# different results.
2121

2222
IF(MSVC)
23+
SET(HAVE_LLVM_LIBCPP CACHE INTERNAL "")
2324
SET(HAVE_ACCESS 1 CACHE INTERNAL "")
2425
SET(HAVE_AIO_H CACHE INTERNAL "")
2526
SET(HAVE_AIO_READ CACHE INTERNAL "")

config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/* Headers we may want to use. */
2020
#cmakedefine STDC_HEADERS 1
2121
#cmakedefine _GNU_SOURCE 1
22+
#cmakedefine HAVE_LLVM_LIBCPP 1
2223
#cmakedefine HAVE_ALLOCA_H 1
2324
#cmakedefine HAVE_AIO_H 1
2425
#cmakedefine HAVE_ARPA_INET_H 1

configure.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ INCLUDE (CheckLibraryExists)
2121
INCLUDE (CheckFunctionExists)
2222
INCLUDE (CheckCCompilerFlag)
2323
INCLUDE (CheckCSourceRuns)
24+
INCLUDE (CheckCXXSourceRuns)
2425
INCLUDE (CheckSymbolExists)
2526

2627

@@ -86,6 +87,19 @@ IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
8687
ENDIF()
8788
ENDIF()
8889

90+
# Check to see if we are using LLVM's libc++ rather than e.g. libstd++
91+
# Can then check HAVE_LLBM_LIBCPP later without including e.g. ciso646.
92+
CHECK_CXX_SOURCE_RUNS("
93+
#include <ciso646>
94+
int main()
95+
{
96+
#ifdef _LIBCPP_VERSION
97+
return 0;
98+
#else
99+
return 1;
100+
#endif
101+
}" HAVE_LLVM_LIBCPP)
102+
89103
MACRO(DIRNAME IN OUT)
90104
GET_FILENAME_COMPONENT(${OUT} ${IN} PATH)
91105
ENDMACRO()

include/my_global.h

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -763,38 +763,28 @@ inline unsigned long long my_double2ulonglong(double d)
763763
#define SIZE_T_MAX (~((size_t) 0))
764764
#endif
765765

766-
#ifndef isfinite
767-
#ifdef HAVE_FINITE
768-
#define isfinite(x) finite(x)
769-
#else
770-
#define finite(x) (1.0 / fabs(x) > 0.0)
771-
#endif /* HAVE_FINITE */
772-
#endif /* isfinite */
773-
774766
#include <math.h>
775-
#ifndef HAVE_ISNAN
776-
#define isnan(x) ((x) != (x))
777-
#endif
778-
C_MODE_START
779-
extern double my_double_isnan(double x);
780-
C_MODE_END
781767

782-
#ifdef HAVE_ISINF
783-
/* Check if C compiler is affected by GCC bug #39228 */
784-
#if !defined(__cplusplus) && defined(HAVE_BROKEN_ISINF)
785-
/* Force store/reload of the argument to/from a 64-bit double */
786-
static inline double my_isinf(double x)
787-
{
788-
volatile double t= x;
789-
return isinf(t);
790-
}
768+
#if (__cplusplus >= 201103L)
769+
/* For C++11 use the new std functions rather than C99 macros. */
770+
#include <cmath>
771+
#define my_isfinite(X) std::isfinite(X)
772+
#define my_isnan(X) std::isnan(X)
773+
#define my_isinf(X) std::isinf(X)
791774
#else
792-
/* System-provided isinf() is available and safe to use */
793-
#define my_isinf(X) isinf(X)
794-
#endif
795-
#else /* !HAVE_ISINF */
796-
#define my_isinf(X) (!finite(X) && !isnan(X))
797-
#endif
775+
#ifdef HAVE_LLVM_LIBCPP /* finite is deprecated in libc++ */
776+
#define my_isfinite(X) isfinite(X)
777+
#else
778+
#define my_isfinite(X) finite(X)
779+
#endif
780+
#define my_isnan(X) isnan(X)
781+
#ifdef HAVE_ISINF
782+
/* System-provided isinf() is available and safe to use */
783+
#define my_isinf(X) isinf(X)
784+
#else /* !HAVE_ISINF */
785+
#define my_isinf(X) (!my_isfinite(X) && !my_isnan(X))
786+
#endif
787+
#endif /* __cplusplus >= 201103L */
798788

799789
/* Define missing math constants. */
800790
#ifndef M_PI

mysys/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c
2525
my_compress.c my_copy.c my_create.c my_delete.c
2626
my_div.c my_error.c my_file.c my_fopen.c my_fstream.c
2727
my_gethwaddr.c my_getsystime.c my_getwd.c my_compare.c my_init.c
28-
my_isnan.c
2928
my_lib.c my_lock.c my_malloc.c my_mess.c
3029
my_mkdir.c my_mmap.c my_once.c my_open.c my_pread.c my_pthread.c
3130
my_quick.c my_read.c my_redel.c my_rename.c my_seek.c my_sleep.c

mysys/my_isnan.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

sql/field.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ type_conversion_status Field_decimal::store(double nr)
23482348
return TYPE_WARN_OUT_OF_RANGE;
23492349
}
23502350

2351-
if (!isfinite(nr)) // Handle infinity as special case
2351+
if (!my_isfinite(nr)) // Handle infinity as special case
23522352
{
23532353
overflow(nr < 0.0);
23542354
return TYPE_WARN_OUT_OF_RANGE;
@@ -4492,7 +4492,7 @@ type_conversion_status Field_double::store(longlong nr, bool unsigned_val)
44924492

44934493
bool Field_real::truncate(double *nr, double max_value)
44944494
{
4495-
if (isnan(*nr))
4495+
if (my_isnan(*nr))
44964496
{
44974497
*nr= 0;
44984498
set_null();

sql/item_func.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Item_func :public Item_result_field
228228
void * arg, traverse_order order);
229229
inline double fix_result(double value)
230230
{
231-
if (isfinite(value))
231+
if (my_isfinite(value))
232232
return value;
233233
null_value=1;
234234
return 0.0;
@@ -262,7 +262,7 @@ class Item_func :public Item_result_field
262262
*/
263263
inline double check_float_overflow(double value)
264264
{
265-
return isfinite(value) ? value : raise_float_overflow();
265+
return my_isfinite(value) ? value : raise_float_overflow();
266266
}
267267
/**
268268
Throw an error if the input BIGINT value represented by the

sql/item_strfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2694,7 +2694,7 @@ String *Item_func_format::val_str_ascii(String *str)
26942694
return 0; /* purecov: inspected */
26952695
nr= my_double_round(nr, (longlong) dec, FALSE, FALSE);
26962696
str->set_real(nr, dec, &my_charset_numeric);
2697-
if (isnan(nr) || my_isinf(nr))
2697+
if (my_isnan(nr) || my_isinf(nr))
26982698
return str;
26992699
str_length=str->length();
27002700
}

0 commit comments

Comments
 (0)