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 }