From 3849ce1ea05622e6fea688a20ff3838bd730b85b Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:22:35 -0600 Subject: [PATCH] Safeguard against any potential static init order issues, mentioned in #109 --- src/assert.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/assert.cpp b/src/assert.cpp index 1ea41f3..9e98ed7 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -448,16 +448,19 @@ namespace libassert { } } - static std::atomic failure_handler = default_failure_handler; + static auto& get_failure_handler() { + static std::atomic handler = default_failure_handler; + return handler; + } LIBASSERT_ATTR_COLD LIBASSERT_EXPORT void set_failure_handler(void (*handler)(const assertion_info&)) { - failure_handler = handler; + get_failure_handler() = handler; } namespace detail { LIBASSERT_ATTR_COLD LIBASSERT_EXPORT void fail(const assertion_info& info) { - failure_handler.load()(info); + get_failure_handler().load()(info); } }