From 9f4492da61df636604841260ed919cfa738a4b1c Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 6 Dec 2024 12:20:06 +0200 Subject: [PATCH] Fixed warnings --- include/spdlog/fmt/bin_to_hex.h | 1 + include/spdlog/sinks/hourly_file_sink.h | 6 +++--- include/spdlog/sinks/msvc_sink.h | 2 +- src/details/file_helper.cpp | 6 ++++-- tests/test_file_helper.cpp | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 280e8e0f..86bfed1e 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -121,6 +121,7 @@ struct fmt::formatter, char> { show_ascii = true; } break; + default:; } ++it; diff --git a/include/spdlog/sinks/hourly_file_sink.h b/include/spdlog/sinks/hourly_file_sink.h index d1460113..23a6e77b 100644 --- a/include/spdlog/sinks/hourly_file_sink.h +++ b/include/spdlog/sinks/hourly_file_sink.h @@ -28,11 +28,11 @@ struct hourly_filename_calculator { static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { filename_t basename, ext; std::tie(basename, ext) = details::os::split_by_extension(filename); - std::basic_ostringstream oss; + std::basic_ostringstream oss; oss << basename.native() << '_' << std::setfill(SPDLOG_FILENAME_T('0')) << std::setw(4) << now_tm.tm_year + 1900 << '-' << std::setw(2) << now_tm.tm_mon + 1 << '-' << std::setw(2) << now_tm.tm_mday << '_' << std::setw(2) << now_tm.tm_hour << ext.native(); - return oss.str(); + return oss.str(); } }; @@ -47,7 +47,7 @@ template class hourly_file_sink final : public base_sink { public: // create hourly file sink which rotates on given time - hourly_file_sink(filename_t base_filename, + explicit hourly_file_sink(filename_t base_filename, bool truncate = false, uint16_t max_files = 0, const file_event_handlers &event_handlers = {}) diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index 4b1535c0..e2e0dd13 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -21,7 +21,7 @@ template class msvc_sink final : public base_sink { public: msvc_sink() = default; - msvc_sink(bool check_debugger_present) + explicit msvc_sink(bool check_debugger_present) : check_debugger_present_{check_debugger_present} {} protected: diff --git a/src/details/file_helper.cpp b/src/details/file_helper.cpp index efc3160a..17016be3 100644 --- a/src/details/file_helper.cpp +++ b/src/details/file_helper.cpp @@ -29,9 +29,11 @@ void file_helper::open(const filename_t &fname, bool truncate) { if (event_handlers_.before_open) { event_handlers_.before_open(filename_); } + + // create containing folder if not exists already. + os::create_dir(os::dir_name(fname)); + for (int tries = 0; tries < open_tries_; ++tries) { - // create containing folder if not exists already. - os::create_dir(os::dir_name(fname)); if (truncate) { // Truncate by opening-and-closing a tmp file in "wb" mode, always // opening the actual log-we-write-to in "ab" mode, since that diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index bd5c18fe..3b61ff2c 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -9,7 +9,7 @@ using spdlog::details::file_helper; -static void write_with_helper(file_helper &helper, size_t howmany) { +static void write_with_helper(const file_helper &helper, size_t howmany) { spdlog::memory_buf_t formatted; spdlog::fmt_lib::format_to(std::back_inserter(formatted), "{}", std::string(howmany, '1')); helper.write(formatted);