Skip to content

Commit

Permalink
minor improvements to assert signatures and silence lints
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkelSchubert committed Sep 8, 2024
1 parent 1d15959 commit c7666f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace adapterremoval {
terminate(const std::string& message);

void
debug_raise_assert(const char* funcname,
const char* filename,
debug_raise_assert(std::string_view funcname,
std::string_view filename,
unsigned lineno,
const std::string& test,
const std::string& msg)
std::string_view test,
std::string_view msg)
{
std::ostringstream message;

Expand Down
25 changes: 9 additions & 16 deletions src/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
\*************************************************************************/
#pragma once

#include <string> // for string
#include <string_view> // for string_view

namespace adapterremoval {

Expand All @@ -27,11 +27,11 @@ namespace adapterremoval {
* instructions for how to report the problem.
*/
[[noreturn]] void
debug_raise_assert(const char* funcname,
const char* filename,
debug_raise_assert(std::string_view funcname,
std::string_view filename,
unsigned lineno,
const std::string& test,
const std::string& msg);
std::string_view test,
std::string_view msg);

#ifdef __has_builtin
#if __has_builtin(__builtin_expect)
Expand All @@ -48,28 +48,21 @@ debug_raise_assert(const char* funcname,
/** Custom assert which prints various information on failure; always enabled */
#define AR_REQUIRE_2_(test, msg) \
do { \
/* NOLINTNEXTLINE(readability-simplify-boolean-expr) */ \
if (AR_UNLIKELY(!(test))) { \
debug_raise_assert(static_cast<const char*>(__FUNCTION__), \
static_cast<const char*>(__FILE__), \
__LINE__, \
#test, \
msg); \
debug_raise_assert(__FUNCTION__, __FILE__, __LINE__, #test, msg); \
} \
} while (0)

#define AR_REQUIRE_1_(test) AR_REQUIRE_2_(test, std::string())
#define AR_REQUIRE_1_(test) AR_REQUIRE_2_(test, {})

#define AR_REQUIRE_GET_(_1, _2, NAME, ...) NAME
#define AR_REQUIRE(...) \
AR_REQUIRE_GET_(__VA_ARGS__, AR_REQUIRE_2_, AR_REQUIRE_1_, )(__VA_ARGS__)

/** Raise an assert failure with a user-specified message. */
#define AR_FAIL(msg) \
adapterremoval::debug_raise_assert(static_cast<const char*>(__FUNCTION__), \
static_cast<const char*>(__FILE__), \
__LINE__, \
std::string(), \
msg)
adapterremoval::debug_raise_assert(__FUNCTION__, __FILE__, __LINE__, {}, msg)

#define AR_MERGE1_(a, b) a##b
#define AR_MERGE_(a, b) AR_MERGE1_(a, b)
Expand Down

0 comments on commit c7666f0

Please sign in to comment.