From 473726d2e5032e163559bd5da7c8cde980b7edd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=80=98=E5=91=88?= <40971483+YunchengLiu@users.noreply.github.com> Date: Mon, 17 Oct 2022 23:16:51 +0800 Subject: [PATCH] Use 'SPDLOG_FMT_RUNTIME' to fix compilation error throwed MSVC and fmt 9.1.x --- include/spdlog/sinks/daily_file_sink.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index b07b771d..c1f161af 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -78,7 +78,14 @@ struct daily_filename_format_calculator // generate fmt datetime format string, e.g. {:%Y-%m-%d}. filename_t fmt_filename = fmt::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{{:{}}}")), filename); # if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES) // for some reason msvc doesn't allow fmt::runtime(..) with wchar here - return fmt::format(fmt_filename, now_tm); +# if FMT_VERSION >= 90101 + // fmt 9.1.x added compile-time checks for wide strings + // so when compiled with MSVC and this or later version of fmt + // here should use 'SPDLOG_FMT_RUNTIME' to enable 'fmt::runtime(...)' for wchar to avoid compile error + return fmt::format(SPDLOG_FMT_RUNTIME(fmt_filename), now_tm); +# else + return fmt::format(fmt_filename, now_tm); +# endif # else return fmt::format(SPDLOG_FMT_RUNTIME(fmt_filename), now_tm); # endif