From 0c4fb032e44279e3b4bfe037d84dd8991b8e5c06 Mon Sep 17 00:00:00 2001 From: Keith Kraus Date: Fri, 13 Oct 2023 03:00:00 -0400 Subject: [PATCH] Match SPDLOG_CONSTEXPR_FUNC to FMT_CONSTEXPR (#2901) * Modify the condition of SPDLOG_CONSTEXPR_FUNC to match that of fmt --- include/spdlog/common.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index c46c1531d..1269c14af 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -65,14 +65,23 @@ #if defined(_MSC_VER) && (_MSC_VER < 1900) #define SPDLOG_NOEXCEPT _NOEXCEPT #define SPDLOG_CONSTEXPR - #define SPDLOG_CONSTEXPR_FUNC inline #else #define SPDLOG_NOEXCEPT noexcept #define SPDLOG_CONSTEXPR constexpr - #if __cplusplus >= 201402L - #define SPDLOG_CONSTEXPR_FUNC constexpr +#endif + +// If building with std::format, can just use constexpr, otherwise if building with fmt +// SPDLOG_CONSTEXPR_FUNC needs to be set the same as FMT_CONSTEXPR to avoid situations where +// a constexpr function in spdlog could end up calling a non-constexpr function in fmt +// depending on the compiler +// If fmt determines it can't use constexpr, we should inline the function instead +#ifdef SPDLOG_USE_STD_FORMAT + #define SPDLOG_CONSTEXPR_FUNC constexpr +#else // Being built with fmt + #if FMT_USE_CONSTEXPR + #define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR #else - #define SPDLOG_CONSTEXPR_FUNC inline + #define SPDLOG_CONSTEXPR_FUNC inline #endif #endif