From 7e95963940c6dc5e0cfe46bd59bb9119d1fa19a1 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sun, 19 Dec 2021 15:04:47 +0400 Subject: [PATCH 1/4] Useless cast --- include/spdlog/details/os-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 16f3d2e9..8762d847 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -407,7 +407,7 @@ SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT #ifdef _WIN32 return static_cast(::GetCurrentProcessId()); #else - return static_cast(::getpid()); + return ::getpid(); #endif } From f81cb9f3652c940e5b83e9d25d84c9e6d85e1bd1 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sun, 19 Dec 2021 21:05:21 +0400 Subject: [PATCH 2/4] Revert "Useless cast" This reverts commit 7e95963940c6dc5e0cfe46bd59bb9119d1fa19a1. --- include/spdlog/details/os-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 8762d847..16f3d2e9 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -407,7 +407,7 @@ SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT #ifdef _WIN32 return static_cast(::GetCurrentProcessId()); #else - return ::getpid(); + return static_cast(::getpid()); #endif } From f096c615c36cd9217fbd1f8642e4a33fb6701558 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sun, 19 Dec 2021 21:37:21 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=94=A5=20conditional=5Fcast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/spdlog/common.h | 18 ++++++++++++++++-- include/spdlog/details/os-inl.h | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 9903463c..620b4757 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -30,7 +30,7 @@ # define SPDLOG_API __declspec(dllimport) # endif # else // !defined(_WIN32) -# define SPDLOG_API __attribute__((visibility ("default"))) +# define SPDLOG_API __attribute__((visibility("default"))) # endif # else // !defined(SPDLOG_SHARED_LIB) # define SPDLOG_API @@ -320,13 +320,27 @@ struct file_event_handlers }; namespace details { + +// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) +template::value, int> = 0> +constexpr T conditional_static_cast(U value) +{ + return static_cast(value); +} + +template::value, int> = 0> +constexpr T conditional_static_cast(U value) +{ + return value; +} + // make_unique support for pre c++14 #if __cplusplus >= 201402L // C++14 and beyond using std::make_unique; #else template -std::unique_ptr make_unique(Args &&... args) +std::unique_ptr make_unique(Args &&...args) { static_assert(!std::is_array::value, "arrays not supported"); return std::unique_ptr(new T(std::forward(args)...)); diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 16f3d2e9..e094e0f7 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -405,9 +405,9 @@ SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT { #ifdef _WIN32 - return static_cast(::GetCurrentProcessId()); + return conditional_static_cast(::GetCurrentProcessId()); #else - return static_cast(::getpid()); + return conditional_static_cast(::getpid()); #endif } From a087dee98a59bb70472960d098a69f94ed73b6e3 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sun, 19 Dec 2021 21:48:39 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=9A=A7=20fix=20building=20with=20c++1?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/spdlog/common.h | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 620b4757..d391b11b 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -321,24 +321,15 @@ struct file_event_handlers namespace details { -// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) -template::value, int> = 0> -constexpr T conditional_static_cast(U value) -{ - return static_cast(value); -} - -template::value, int> = 0> -constexpr T conditional_static_cast(U value) -{ - return value; -} - // make_unique support for pre c++14 #if __cplusplus >= 201402L // C++14 and beyond +using std::enable_if_t; using std::make_unique; #else +template +using enable_if_t = typename std::enable_if::type; + template std::unique_ptr make_unique(Args &&...args) { @@ -346,6 +337,20 @@ std::unique_ptr make_unique(Args &&...args) return std::unique_ptr(new T(std::forward(args)...)); } #endif + +// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) +template::value, int> = 0> +constexpr T conditional_static_cast(U value) +{ + return static_cast(value); +} + +template::value, int> = 0> +constexpr T conditional_static_cast(U value) +{ + return value; +} + } // namespace details } // namespace spdlog