From 53d223b45f5a0138e12516d1a83fdfe317ab61eb Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Mon, 11 Jan 2021 11:15:29 +0100 Subject: [PATCH 1/2] add constexpr to SPDLOG_LEVEL_NAMES declaration for #1791 --- include/spdlog/common-inl.h | 4 ++-- include/spdlog/common.h | 2 +- include/spdlog/pattern_formatter-inl.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index be0d8f8e..41d9b163 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -9,11 +9,11 @@ namespace spdlog { namespace level { -static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; +static FMT_CONSTEXPR string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; -SPDLOG_INLINE string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT +SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { return level_string_views[l]; } diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 1c39995e..d02c0fb4 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -163,7 +163,7 @@ enum level_enum } #endif -SPDLOG_API string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; +SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index 5a1c5eaf..1cfca192 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -127,7 +127,7 @@ public: void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - string_view_t &level_name = level::to_string_view(msg.level); + const string_view_t &level_name = level::to_string_view(msg.level); ScopedPadder p(level_name.size(), padinfo_, dest); fmt_helper::append_string_view(level_name, dest); } From ede8d848849ef314c65c1c993e287d5ba1cf75f1 Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Mon, 11 Jan 2021 11:25:27 +0100 Subject: [PATCH 2/2] fix constexpr declaration for c++11 --- include/spdlog/common-inl.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index 41d9b163..9c967248 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -9,7 +9,11 @@ namespace spdlog { namespace level { -static FMT_CONSTEXPR string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; + +#if __cplusplus >= 201402L +constexpr +#endif +static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;