Work around some nonsense
This commit is contained in:
parent
d4a55a5554
commit
6b52b5cd3d
@ -54,11 +54,11 @@ namespace detail {
|
|||||||
const char* expression,
|
const char* expression,
|
||||||
const char* signature,
|
const char* signature,
|
||||||
source_location location,
|
source_location location,
|
||||||
const std::string& message = ""
|
const char* message
|
||||||
) {
|
) {
|
||||||
const char* action = assert_actions[static_cast<std::underlying_type<assert_type>::type>(type)];
|
const char* action = assert_actions[static_cast<std::underlying_type<assert_type>::type>(type)];
|
||||||
const char* name = assert_names[static_cast<std::underlying_type<assert_type>::type>(type)];
|
const char* name = assert_names[static_cast<std::underlying_type<assert_type>::type>(type)];
|
||||||
if(message == "") {
|
if(message == nullptr) {
|
||||||
throw internal_error(
|
throw internal_error(
|
||||||
"Cpptrace {} failed at {}:{}: {}\n"
|
"Cpptrace {} failed at {}:{}: {}\n"
|
||||||
" {}({});\n",
|
" {}({});\n",
|
||||||
@ -69,7 +69,7 @@ namespace detail {
|
|||||||
throw internal_error(
|
throw internal_error(
|
||||||
"Cpptrace {} failed at {}:{}: {}: {}\n"
|
"Cpptrace {} failed at {}:{}: {}: {}\n"
|
||||||
" {}({});\n",
|
" {}({});\n",
|
||||||
action, location.file, location.line, signature, message.c_str(),
|
action, location.file, location.line, signature, message,
|
||||||
name, expression
|
name, expression
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -100,25 +100,13 @@ namespace detail {
|
|||||||
|
|
||||||
#define PHONY_USE(E) (nullfn<decltype(E)>())
|
#define PHONY_USE(E) (nullfn<decltype(E)>())
|
||||||
|
|
||||||
// Workaround a compiler warning
|
// Work around a compiler warning
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool as_bool(T&& value) {
|
bool as_bool(T&& value) {
|
||||||
return static_cast<bool>(std::forward<T>(value));
|
return static_cast<bool>(std::forward<T>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check condition in both debug and release. std::runtime_error on failure.
|
// Work around a compiler warning
|
||||||
#define VERIFY(c, ...) ( \
|
|
||||||
(::cpptrace::detail::as_bool(c)) \
|
|
||||||
? static_cast<void>(0) \
|
|
||||||
: (::cpptrace::detail::assert_fail)( \
|
|
||||||
::cpptrace::detail::assert_type::verify, \
|
|
||||||
#c, \
|
|
||||||
CPPTRACE_PFUNC, \
|
|
||||||
{}, \
|
|
||||||
##__VA_ARGS__) \
|
|
||||||
)
|
|
||||||
|
|
||||||
// Workaround a compiler warning
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string as_string(T&& value) {
|
std::string as_string(T&& value) {
|
||||||
return std::string(std::forward<T>(value));
|
return std::string(std::forward<T>(value));
|
||||||
@ -131,17 +119,47 @@ namespace detail {
|
|||||||
// Check condition in both debug and release. std::runtime_error on failure.
|
// Check condition in both debug and release. std::runtime_error on failure.
|
||||||
#define PANIC(...) ((::cpptrace::detail::panic)(CPPTRACE_PFUNC, {}, ::cpptrace::detail::as_string(__VA_ARGS__)))
|
#define PANIC(...) ((::cpptrace::detail::panic)(CPPTRACE_PFUNC, {}, ::cpptrace::detail::as_string(__VA_ARGS__)))
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void assert_impl(
|
||||||
|
T condition,
|
||||||
|
const char* message,
|
||||||
|
assert_type type,
|
||||||
|
const char* args,
|
||||||
|
const char* signature,
|
||||||
|
source_location location
|
||||||
|
) {
|
||||||
|
if(as_bool(condition)) {
|
||||||
|
assert_fail(type, args, signature, location, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void assert_impl(
|
||||||
|
T condition,
|
||||||
|
assert_type type,
|
||||||
|
const char* args,
|
||||||
|
const char* signature,
|
||||||
|
source_location location
|
||||||
|
) {
|
||||||
|
assert_impl(
|
||||||
|
condition,
|
||||||
|
nullptr,
|
||||||
|
type,
|
||||||
|
args,
|
||||||
|
signature,
|
||||||
|
location
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check condition in both debug and release. std::runtime_error on failure.
|
||||||
|
#define VERIFY(...) ( \
|
||||||
|
assert_impl(__VA_ARGS__, ::cpptrace::detail::assert_type::verify, #__VA_ARGS__, CPPTRACE_PFUNC, {}) \
|
||||||
|
)
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// Check condition in both debug. std::runtime_error on failure.
|
// Check condition in both debug. std::runtime_error on failure.
|
||||||
#define ASSERT(c, ...) ( \
|
#define ASSERT(...) ( \
|
||||||
(::cpptrace::detail::as_bool(c)) \
|
assert_impl(__VA_ARGS__, ::cpptrace::detail::assert_type::assert, #__VA_ARGS__, CPPTRACE_PFUNC, {}) \
|
||||||
? static_cast<void>(0) \
|
|
||||||
: (::cpptrace::detail::assert_fail)( \
|
|
||||||
::cpptrace::detail::assert_type::assert, \
|
|
||||||
#c, \
|
|
||||||
CPPTRACE_PFUNC, \
|
|
||||||
{}, \
|
|
||||||
##__VA_ARGS__) \
|
|
||||||
)
|
)
|
||||||
#else
|
#else
|
||||||
// Check condition in both debug. std::runtime_error on failure.
|
// Check condition in both debug. std::runtime_error on failure.
|
||||||
|
|||||||
@ -214,7 +214,7 @@ namespace microfmt {
|
|||||||
std::string str;
|
std::string str;
|
||||||
std::size_t arg_i = 0;
|
std::size_t arg_i = 0;
|
||||||
auto it = fmt_begin;
|
auto it = fmt_begin;
|
||||||
auto peek = [&] (std::size_t dist = 1) -> char { // 0 on failure
|
auto peek = [&] (std::size_t dist) -> char { // 0 on failure
|
||||||
if(it != fmt_end) {
|
if(it != fmt_end) {
|
||||||
return *(it + dist);
|
return *(it + dist);
|
||||||
} else {
|
} else {
|
||||||
@ -236,7 +236,7 @@ namespace microfmt {
|
|||||||
};
|
};
|
||||||
while(it != fmt_end) {
|
while(it != fmt_end) {
|
||||||
if(*it == '{') {
|
if(*it == '{') {
|
||||||
if(peek() == '{') {
|
if(peek(1) == '{') {
|
||||||
// try to handle escape
|
// try to handle escape
|
||||||
str += '{';
|
str += '{';
|
||||||
it++;
|
it++;
|
||||||
@ -255,7 +255,7 @@ namespace microfmt {
|
|||||||
if(width != -1) {
|
if(width != -1) {
|
||||||
options.width = width;
|
options.width = width;
|
||||||
} else if(*it == '{') { // try to parse variable width
|
} else if(*it == '{') { // try to parse variable width
|
||||||
MICROFMT_ASSERT(peek() == '}');
|
MICROFMT_ASSERT(peek(1) == '}');
|
||||||
it += 2;
|
it += 2;
|
||||||
MICROFMT_ASSERT(arg_i < args.size());
|
MICROFMT_ASSERT(arg_i < args.size());
|
||||||
options.width = args[arg_i++].unwrap_int();
|
options.width = args[arg_i++].unwrap_int();
|
||||||
@ -285,7 +285,7 @@ namespace microfmt {
|
|||||||
}
|
}
|
||||||
} else if(*it == '}') {
|
} else if(*it == '}') {
|
||||||
// parse }} escape
|
// parse }} escape
|
||||||
if(peek() == '}') {
|
if(peek(1) == '}') {
|
||||||
str += '}';
|
str += '}';
|
||||||
it++;
|
it++;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user