Add assertion failure handler
This commit is contained in:
@ -24,6 +24,7 @@ cc_library(
|
||||
],
|
||||
srcs = [
|
||||
"allocator.cpp",
|
||||
"assert.cpp",
|
||||
"format.cpp",
|
||||
"format_float.cpp",
|
||||
"print.cpp",
|
||||
|
11
asl/assert.cpp
Normal file
11
asl/assert.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "asl/assert.hpp"
|
||||
#include "asl/print.hpp"
|
||||
|
||||
|
||||
void asl::report_assert_failure(const char* msg, const source_location& sl)
|
||||
{
|
||||
eprint("------------------------------------------------------------\n");
|
||||
eprint("Assertion failure at {}, line {}:\n", sl.file, sl.line);
|
||||
eprint("{}\n", msg);
|
||||
eprint("------------------------------------------------------------\n");
|
||||
}
|
@ -1,6 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "asl/config.hpp"
|
||||
#include "asl/meta.hpp"
|
||||
|
||||
namespace asl
|
||||
{
|
||||
|
||||
void report_assert_failure( const char* msg, const source_location& sl = source_location{});
|
||||
|
||||
} // namespace asl
|
||||
|
||||
#if ASL_COMPILER_CLANG_CL
|
||||
#define ASL_DEBUG_BREAK() __debugbreak()
|
||||
@ -10,8 +18,16 @@
|
||||
|
||||
#define ASL_ASSERT(...) \
|
||||
if (__VA_ARGS__) {} \
|
||||
else { ASL_DEBUG_BREAK(); }
|
||||
else \
|
||||
{ \
|
||||
::asl::report_assert_failure(#__VA_ARGS__); \
|
||||
ASL_DEBUG_BREAK(); \
|
||||
}
|
||||
|
||||
#define ASL_ASSERT_RELEASE(...) \
|
||||
if (__VA_ARGS__) {} \
|
||||
else { ASL_DEBUG_BREAK(); }
|
||||
else \
|
||||
{ \
|
||||
::asl::report_assert_failure(#__VA_ARGS__); \
|
||||
ASL_DEBUG_BREAK(); \
|
||||
}
|
||||
|
@ -114,6 +114,8 @@ private:
|
||||
// NOLINTNEXTLINE(*-rvalue-reference-param-not-moved)
|
||||
void move_from_other(buffer&& other)
|
||||
{
|
||||
ASL_ASSERT(size() == 0 && !is_on_heap());
|
||||
|
||||
if (other.is_on_heap())
|
||||
{
|
||||
m_data = other.m_data;
|
||||
|
13
asl/meta.hpp
13
asl/meta.hpp
@ -4,6 +4,19 @@
|
||||
|
||||
namespace asl {
|
||||
|
||||
struct source_location
|
||||
{
|
||||
const char* file;
|
||||
int line;
|
||||
|
||||
explicit source_location(
|
||||
const char* file = __builtin_FILE(),
|
||||
int line = __builtin_LINE())
|
||||
: file{file}
|
||||
, line{line}
|
||||
{}
|
||||
};
|
||||
|
||||
struct empty {};
|
||||
|
||||
template<typename T> struct id { using type = T; };
|
||||
|
Reference in New Issue
Block a user