From 546e2cbf5e95eace45ffd197a1220ce5ee551475 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 13 Mar 2019 22:14:53 +0100 Subject: [PATCH] :rotating_light: fixed some warnings --- Makefile | 1 + include/nlohmann/detail/output/serializer.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- test/src/unit-regression.cpp | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 297443a5..f16b209a 100644 --- a/Makefile +++ b/Makefile @@ -136,6 +136,7 @@ pedantic_clang: -Wno-float-equal \ -Wno-switch-enum -Wno-covered-switch-default \ -Wno-c++2a-compat \ + -Wno-c++17-extensions \ -Wno-padded" # calling GCC with most warnings diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 9994372d..74c2d771 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -620,7 +620,7 @@ class serializer if (is_negative) { *buffer_ptr = '-'; - abs_value = static_cast(-1 - x) + 1; + abs_value = static_cast(std::abs(static_cast(x))); // account one more byte for the minus sign n_chars = 1 + count_digits(abs_value); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index ded6c2bc..8f61edc7 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -11533,7 +11533,7 @@ class serializer if (is_negative) { *buffer_ptr = '-'; - abs_value = static_cast(-1 - x) + 1; + abs_value = static_cast(std::abs(static_cast(x))); // account one more byte for the minus sign n_chars = 1 + count_digits(abs_value); diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 975b9239..822cac96 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -1762,7 +1762,7 @@ TEST_CASE("regression tests") -54, -28, -26 }; std::string s; - for (int i = 0; i < sizeof(data) / sizeof(int); i++) + for (unsigned i = 0; i < sizeof(data) / sizeof(int); i++) { s += static_cast(data[i]); }