From 71ed5abbd13e479ffb4e3ed4739e77622afb5835 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Fri, 27 Sep 2019 12:08:49 +0200 Subject: [PATCH] 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. --- src/language/ASTNode.hpp | 2 +- src/utils/PugsAssert.hpp | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/language/ASTNode.hpp b/src/language/ASTNode.hpp index 31b12b1e5..92aeb29e0 100644 --- a/src/language/ASTNode.hpp +++ b/src/language/ASTNode.hpp @@ -28,7 +28,7 @@ struct ASTNode : public parse_tree::basic_node<ASTNode> void execute(ExecUntilBreakOrContinue& exec_policy) { - Assert(static_cast<bool>(m_node_processor)); + Assert(m_node_processor, "Undefined node processor"); if (exec_policy.exec()) { m_node_processor->execute(exec_policy); } diff --git a/src/utils/PugsAssert.hpp b/src/utils/PugsAssert.hpp index 1ca85e009..d31c9ef3a 100644 --- a/src/utils/PugsAssert.hpp +++ b/src/utils/PugsAssert.hpp @@ -50,18 +50,11 @@ class AssertError ~AssertError() = default; }; -PRAGMA_DIAGNOSTIC_IGNORED_WATTRIBUTES -inline bool __attribute__((analyzer_noreturn)) _pugs_assert(const bool& assert) -{ - return assert; -} -PRAGMA_DIAGNOSTIC_POP - #ifdef NDEBUG // Useless test is there to check syntax even in optimized mode. Costs nothing. #define Assert(assertion, ...) \ - if (not _pugs_assert(assertion)) { \ + if (not static_cast<bool>(assertion)) { \ using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \ } @@ -69,7 +62,7 @@ PRAGMA_DIAGNOSTIC_POP #else // NDEBUG #define Assert(assertion, ...) \ - if (not _pugs_assert(assertion)) { \ + if (not static_cast<bool>(assertion)) { \ using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \ if constexpr (std::tuple_size_v<vargs_t> == 0) { \ -- GitLab