diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index be0d8f8e..9c967248 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -9,11 +9,15 @@ namespace spdlog { namespace level { + +#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; -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 35342317..2ba355c7 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -166,7 +166,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 1408bb5c..54346e1e 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -129,7 +129,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); }