diff --git a/include/log/log.hpp b/include/log/log.hpp index d5afc77a..56e6d14a 100644 --- a/include/log/log.hpp +++ b/include/log/log.hpp @@ -70,15 +70,14 @@ ALWAYS_INLINE static auto log(TArgs &&...args) -> void { CIB_LOG(logging::default_flavor_t, logging::level::ERROR, __VA_ARGS__) #define CIB_FATAL(MSG, ...) \ - [] { \ - constexpr auto str = sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__); \ + [](auto &&str) { \ logging::log(__FILE__, __LINE__, str); \ - str.apply([](S s, Args... args) { \ + FWD(str).apply([](S s, Args... args) { \ constexpr auto cts = stdx::ct_string_from_type(s); \ stdx::panic(args...); \ }); \ - }() + }(sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) #define CIB_ASSERT(expr) \ ((expr) ? void(0) : CIB_FATAL("Assertion failure: " #expr)) diff --git a/test/log/log.cpp b/test/log/log.cpp index e5406da2..b388b463 100644 --- a/test/log/log.cpp +++ b/test/log/log.cpp @@ -16,7 +16,7 @@ bool panicked{}; struct injected_handler { template static auto panic(Ts &&...) noexcept -> void { - static_assert(std::string_view{Why} == "Hello"); + static_assert(std::string_view{Why}.starts_with("Hello")); panicked = true; } }; @@ -55,3 +55,10 @@ TEST_CASE("CIB_FATAL pre-formats arguments passed to panic", "[log]") { CIB_FATAL("{}", "Hello"_sc); CHECK(panicked); } + +TEST_CASE("CIB_FATAL can format stack arguments", "[log]") { + panicked = false; + auto x = 42; + CIB_FATAL("Hello {}", x); + CHECK(panicked); +}