From 3cf386390f6948e9f39de7e4611fed452f4be765 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 7 Nov 2021 06:12:34 +1000 Subject: [PATCH] Fix some format string specifier type errors in recent compilers --- debug_posix.cpp | 2 +- log/packet.hpp | 16 ++++++++++++++++ log/scoped.cpp | 2 +- tools/log.cpp | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/debug_posix.cpp b/debug_posix.cpp index 22e6977e..9f8ac185 100644 --- a/debug_posix.cpp +++ b/debug_posix.cpp @@ -82,7 +82,7 @@ prepare_debugger (void) void await_debugger (void) { - LOG_INFO ("awaiting debugger"); + LOG_INFO ("%s", "awaiting debugger"); if (is_debugged ()) breakpoint (); diff --git a/log/packet.hpp b/log/packet.hpp index 79e2fdd7..311a8522 100644 --- a/log/packet.hpp +++ b/log/packet.hpp @@ -20,6 +20,22 @@ namespace cruft::log { { ; } + template + packet ( + level_t _level, + std::string_view _format, + ArgsT &&..._args + ) : packet ( + _level, + fmt::vformat ( + _format, + fmt::make_format_args( + std::forward (_args)... + ) + ) + ) + { ; } + template packet ( level_t _level, diff --git a/log/scoped.cpp b/log/scoped.cpp index 854ff155..c196de3e 100644 --- a/log/scoped.cpp +++ b/log/scoped.cpp @@ -50,7 +50,7 @@ cruft::log::scoped_timer::~scoped_timer () write ( m_level, - "{:f}s, {:s}", + FMT_STRING("{:f}s, {:s}"), float (duration) / 1'000'000'000.f, m_message ); diff --git a/tools/log.cpp b/tools/log.cpp index aedde2d2..7bbbda1b 100644 --- a/tools/log.cpp +++ b/tools/log.cpp @@ -34,8 +34,8 @@ int main (int const argc, char const **argv) auto const count = argc - 3; switch (count) { case 0: cruft::log::write (level, format); break; - case 1: cruft::log::write (level, format, argv[MIN_ARGS + 0]); break; - case 2: cruft::log::write (level, format, argv[MIN_ARGS + 0], argv[MIN_ARGS + 1]); break; + case 1: cruft::log::write (level, std::string_view{format}, argv[MIN_ARGS + 0]); break; + case 2: cruft::log::write (level, std::string_view{format}, argv[MIN_ARGS + 0], argv[MIN_ARGS + 1]); break; } return EXIT_SUCCESS;