Skip to content

Commit 608d3c7

Browse files
authored
Merge pull request #680 from elbeno/fix-log-fatal
🐛 Fix `CIB_FATAL`
2 parents 5726ca9 + 5177a22 commit 608d3c7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

include/log/log.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ ALWAYS_INLINE static auto log(TArgs &&...args) -> void {
7070
CIB_LOG(logging::default_flavor_t, logging::level::ERROR, __VA_ARGS__)
7171

7272
#define CIB_FATAL(MSG, ...) \
73-
[] { \
74-
constexpr auto str = sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__); \
73+
[](auto &&str) { \
7574
logging::log<logging::default_flavor_t, logging::level::FATAL, \
7675
cib_log_env_t>(__FILE__, __LINE__, str); \
77-
str.apply([]<typename S, typename... Args>(S s, Args... args) { \
76+
FWD(str).apply([]<typename S, typename... Args>(S s, Args... args) { \
7877
constexpr auto cts = stdx::ct_string_from_type(s); \
7978
stdx::panic<cts>(args...); \
8079
}); \
81-
}()
80+
}(sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
8281

8382
#define CIB_ASSERT(expr) \
8483
((expr) ? void(0) : CIB_FATAL("Assertion failure: " #expr))

test/log/log.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bool panicked{};
1616
struct injected_handler {
1717
template <stdx::ct_string Why, typename... Ts>
1818
static auto panic(Ts &&...) noexcept -> void {
19-
static_assert(std::string_view{Why} == "Hello");
19+
static_assert(std::string_view{Why}.starts_with("Hello"));
2020
panicked = true;
2121
}
2222
};
@@ -55,3 +55,10 @@ TEST_CASE("CIB_FATAL pre-formats arguments passed to panic", "[log]") {
5555
CIB_FATAL("{}", "Hello"_sc);
5656
CHECK(panicked);
5757
}
58+
59+
TEST_CASE("CIB_FATAL can format stack arguments", "[log]") {
60+
panicked = false;
61+
auto x = 42;
62+
CIB_FATAL("Hello {}", x);
63+
CHECK(panicked);
64+
}

0 commit comments

Comments
 (0)