From fe34b2f357d622c7418f137df910a07af96b0d9f Mon Sep 17 00:00:00 2001 From: Ingo van Lil Date: Mon, 2 Nov 2015 18:33:35 +0100 Subject: [PATCH 1/4] Fix bogus warning when compiling with -Wctor-dtor-privacy --- format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format.h b/format.h index 575ad59e1227..c132352c9930 100644 --- a/format.h +++ b/format.h @@ -911,7 +911,7 @@ struct WCharHelper { template class IsConvertibleToInt { - private: + protected: typedef char yes[1]; typedef char no[2]; From f4d8884af1ab596853f46efd4e85e2c6536e7337 Mon Sep 17 00:00:00 2001 From: Ingo van Lil Date: Mon, 2 Nov 2015 19:14:47 +0100 Subject: [PATCH 2/4] Add casts to fix warnings with -Wconversion --- format.cc | 2 +- format.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/format.cc b/format.cc index aad169eb4bab..962c47055573 100644 --- a/format.cc +++ b/format.cc @@ -1265,7 +1265,7 @@ FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, ArgList args) FMT_FUNC void fmt::print_colored(Color c, CStringRef format, ArgList args) { char escape[] = "\x1b[30m"; - escape[3] = '0' + static_cast(c); + escape[3] = static_cast('0' + c); std::fputs(escape, stdout); print(format, args); std::fputs(RESET_COLOR, stdout); diff --git a/format.h b/format.h index c132352c9930..861c7ce72e2e 100644 --- a/format.h +++ b/format.h @@ -778,7 +778,7 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. - unsigned index = (value % 100) * 2; + unsigned index = static_cast((value % 100) * 2); value /= 100; *--buffer = Data::DIGITS[index + 1]; *--buffer = Data::DIGITS[index]; @@ -2330,7 +2330,7 @@ void BasicWriter::write_int(T value, Spec spec) { Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size)); n = abs_value; do { - *p-- = '0' + (n & 1); + *p-- = static_cast('0' + (n & 1)); } while ((n >>= 1) != 0); break; } @@ -2345,7 +2345,7 @@ void BasicWriter::write_int(T value, Spec spec) { Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size)); n = abs_value; do { - *p-- = '0' + (n & 7); + *p-- = static_cast('0' + (n & 7)); } while ((n >>= 3) != 0); break; } @@ -2810,7 +2810,7 @@ class FormatInt { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. - unsigned index = (value % 100) * 2; + unsigned index = static_cast((value % 100) * 2); value /= 100; *--buffer_end = internal::Data::DIGITS[index + 1]; *--buffer_end = internal::Data::DIGITS[index]; From 9954aa064bcd86d2c133c4ca45aedd63866fa75a Mon Sep 17 00:00:00 2001 From: Ingo van Lil Date: Tue, 3 Nov 2015 11:14:48 +0100 Subject: [PATCH 3/4] Disable GCC sign-compare warning in the header file --- format.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/format.h b/format.h index 861c7ce72e2e..bde8878c766c 100644 --- a/format.h +++ b/format.h @@ -105,6 +105,9 @@ inline uint32_t clzll(uint64_t x) { // Disable the warning about declaration shadowing because it affects too // many valid cases. # pragma GCC diagnostic ignored "-Wshadow" +// Disable the warning about implicit conversions that may change the sign of +// an integer; silencing it otherwise would require many explicit casts. +# pragma GCC diagnostic ignored "-Wsign-conversion" # endif # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ # define FMT_HAS_GXX_CXX11 1 From 41ebedf516476c1cd837c501b3195bbe82a054d9 Mon Sep 17 00:00:00 2001 From: Ingo van Lil Date: Tue, 3 Nov 2015 11:21:09 +0100 Subject: [PATCH 4/4] Fix warning when building with -Wundef and disabled exceptions --- format.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format.cc b/format.cc index 962c47055573..8e23701db73f 100644 --- a/format.cc +++ b/format.cc @@ -52,7 +52,7 @@ using fmt::internal::Arg; // Check if exceptions are disabled. -#if __GNUC__ && !__EXCEPTIONS +#if defined(__GNUC__) && !defined(__EXCEPTIONS) # define FMT_EXCEPTIONS 0 #endif #if defined(_MSC_VER) && !_HAS_EXCEPTIONS