#include "fud_assert.hpp" #include "fud_array.hpp" #include #include #include namespace fud { constexpr std::size_t BITS_PER_OCTAL = 3; constexpr auto MAX_LINE_CHARS = BITS_PER_OCTAL * sizeof(decltype(std::source_location{}.line())) + 3; [[noreturn]] void assertFail(const char* assertion, const std::source_location sourceLocation) { const char* file_name = sourceLocation.file_name(); if (file_name == nullptr) { fputs("Unknown file", stderr); } else { fputs(file_name, stderr); } constexpr std::size_t assertMsgSize = MAX_LINE_CHARS + 3; Array buffer{}; static_cast(std::format_to_n(buffer.data(), buffer.size() - 1U, ":{}:", sourceLocation.line())); buffer[buffer.size() - 1] = '\0'; fputs(buffer.data(), stderr); fputs(sourceLocation.function_name(), stderr); fputs(": ", stderr); fputs(assertion, stderr); std::terminate(); } } // namespace fud