Skip to content
Snippets Groups Projects
Commit 71ed5abb authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Simplify Assert management

Now `Assert(d)` or `Assert(d, "d is undefined")` work properly with
`std::unique_ptr`. Does not require anymore to write
`Assert(static_cast<bool>(d))` which is much more convenient.
parent 8b3805d0
Branches
Tags
1 merge request!37Feature/language
...@@ -28,7 +28,7 @@ struct ASTNode : public parse_tree::basic_node<ASTNode> ...@@ -28,7 +28,7 @@ struct ASTNode : public parse_tree::basic_node<ASTNode>
void void
execute(ExecUntilBreakOrContinue& exec_policy) execute(ExecUntilBreakOrContinue& exec_policy)
{ {
Assert(static_cast<bool>(m_node_processor)); Assert(m_node_processor, "Undefined node processor");
if (exec_policy.exec()) { if (exec_policy.exec()) {
m_node_processor->execute(exec_policy); m_node_processor->execute(exec_policy);
} }
......
...@@ -50,18 +50,11 @@ class AssertError ...@@ -50,18 +50,11 @@ class AssertError
~AssertError() = default; ~AssertError() = default;
}; };
PRAGMA_DIAGNOSTIC_IGNORED_WATTRIBUTES
inline bool __attribute__((analyzer_noreturn)) _pugs_assert(const bool& assert)
{
return assert;
}
PRAGMA_DIAGNOSTIC_POP
#ifdef NDEBUG #ifdef NDEBUG
// Useless test is there to check syntax even in optimized mode. Costs nothing. // Useless test is there to check syntax even in optimized mode. Costs nothing.
#define Assert(assertion, ...) \ #define Assert(assertion, ...) \
if (not _pugs_assert(assertion)) { \ if (not static_cast<bool>(assertion)) { \
using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \
static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \ static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \
} }
...@@ -69,7 +62,7 @@ PRAGMA_DIAGNOSTIC_POP ...@@ -69,7 +62,7 @@ PRAGMA_DIAGNOSTIC_POP
#else // NDEBUG #else // NDEBUG
#define Assert(assertion, ...) \ #define Assert(assertion, ...) \
if (not _pugs_assert(assertion)) { \ if (not static_cast<bool>(assertion)) { \
using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \
static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \ static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \
if constexpr (std::tuple_size_v<vargs_t> == 0) { \ if constexpr (std::tuple_size_v<vargs_t> == 0) { \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment