From a58d7594cb9d2a8948feb94426617002f0e16fd2 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 00:32:13 +0300 Subject: [PATCH] Fixed issue #798 and added -Wconversion compiler flag to build --- CMakeLists.txt | 2 ++ bench/bench.cpp | 6 +++--- bench/latency.cpp | 6 +++--- example/Makefile | 2 +- include/spdlog/details/fmt_helper.h | 12 ++++++------ include/spdlog/sinks/ostream_sink.h | 2 +- tests/Makefile | 2 +- tests/registry.cpp | 4 ++-- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fee56552..3eee0dae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") add_compile_options("-Wall") add_compile_options("-Wextra") + add_compile_options("-Wconversion") add_compile_options("-pedantic") + endif() #--------------------------------------------------------------------------------------- diff --git a/bench/bench.cpp b/bench/bench.cpp index f5a8060b..db14e1af 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -35,8 +35,8 @@ int main(int argc, char *argv[]) int howmany = 1000000; int queue_size = howmany + 2; int threads = 10; - int file_size = 30 * 1024 * 1024; - int rotating_files = 5; + size_t file_size = 30 * 1024 * 1024; + size_t rotating_files = 5; try { @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) for (int i = 0; i < 3; ++i) { - spdlog::init_thread_pool(queue_size, 1); + spdlog::init_thread_pool(static_cast(queue_size), 1); auto as = spdlog::basic_logger_mt("async", "logs/basic_async.log", true); bench_mt(howmany, as, threads); spdlog::drop("async"); diff --git a/bench/latency.cpp b/bench/latency.cpp index 374eafb0..dcc6965c 100644 --- a/bench/latency.cpp +++ b/bench/latency.cpp @@ -35,8 +35,8 @@ int main(int, char *[]) int howmany = 1000000; int queue_size = howmany + 2; int threads = 10; - int file_size = 30 * 1024 * 1024; - int rotating_files = 5; + size_t file_size = 30 * 1024 * 1024; + size_t rotating_files = 5; try { @@ -82,7 +82,7 @@ int main(int, char *[]) for (int i = 0; i < 3; ++i) { - spdlog::init_thread_pool(queue_size, 1); + spdlog::init_thread_pool(static_cast(queue_size), 1); auto as = spdlog::basic_logger_mt("async", "logs/basic_async.log", true); bench_mt(howmany, as, threads); spdlog::drop("async"); diff --git a/example/Makefile b/example/Makefile index 01bdf507..bd6b2922 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,5 +1,5 @@ CXX ?= g++ -CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 +CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 -Wconversion CXX_RELEASE_FLAGS = -O3 -march=native CXX_DEBUG_FLAGS= -g diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index eabf93b5..a94c7c5e 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -54,14 +54,14 @@ inline void pad2(int n, fmt::basic_memory_buffer &dest) } if (n > 9) // 10-99 { - dest.push_back('0' + static_cast(n / 10)); - dest.push_back('0' + static_cast(n % 10)); + dest.push_back(static_cast('0' + n / 10)); + dest.push_back(static_cast('0' + n % 10)); return; } if (n >= 0) // 0-9 { dest.push_back('0'); - dest.push_back('0' + static_cast(n)); + dest.push_back(static_cast('0' + n)); return; } // negatives (unlikely, but just in case, let fmt deal with it) @@ -86,15 +86,15 @@ inline void pad3(int n, fmt::basic_memory_buffer &dest) if (n > 9) // 10-99 { dest.push_back('0'); - dest.push_back('0' + static_cast(n / 10)); - dest.push_back('0' + static_cast(n % 10)); + dest.push_back(static_cast('0' + n / 10)); + dest.push_back(static_cast('0' + n % 10)); return; } if (n >= 0) { dest.push_back('0'); dest.push_back('0'); - dest.push_back('0' + static_cast(n)); + dest.push_back(static_cast('0' + n)); return; } // negatives (unlikely, but just in case let fmt deal with it) diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 5f31993c..00c15959 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -30,7 +30,7 @@ protected: { fmt::memory_buffer formatted; sink::formatter_->format(msg, formatted); - ostream_.write(formatted.data(), formatted.size()); + ostream_.write(formatted.data(), static_cast(formatted.size())); if (force_flush_) ostream_.flush(); } diff --git a/tests/Makefile b/tests/Makefile index 00c7c589..bec3026d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,5 @@ CXX ?= g++ -CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O3 -I../include -fmax-errors=1 +CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -Wconversion -O3 -I../include -fmax-errors=1 LDPFALGS = -pthread CPP_FILES := $(wildcard *.cpp) diff --git a/tests/registry.cpp b/tests/registry.cpp index 29bd1fc0..1b841a4c 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -9,7 +9,7 @@ TEST_CASE("register_drop", "[registry]") spdlog::create(tested_logger_name); REQUIRE(spdlog::get(tested_logger_name) != nullptr); // Throw if registring existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex&); + REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex &); } TEST_CASE("explicit register" @@ -20,7 +20,7 @@ TEST_CASE("explicit register" spdlog::register_logger(logger); REQUIRE(spdlog::get(tested_logger_name) != nullptr); // Throw if registring existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex&); + REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex &); } TEST_CASE("apply_all"