From f1b84730923d3ea02bca88d7a74f1e4f6bf86ca0 Mon Sep 17 00:00:00 2001 From: silverqx Date: Fri, 2 Aug 2024 20:55:31 +0200 Subject: [PATCH] enhanced NotNull Use Q_ASSERT_X() for Debug builds. --- .../common/include/orm/drivers/utils/notnull.hpp | 16 +++++++++++++++- include/orm/utils/notnull.hpp | 14 +++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/common/include/orm/drivers/utils/notnull.hpp b/drivers/common/include/orm/drivers/utils/notnull.hpp index c5adccc09..5b227a31e 100644 --- a/drivers/common/include/orm/drivers/utils/notnull.hpp +++ b/drivers/common/include/orm/drivers/utils/notnull.hpp @@ -7,7 +7,11 @@ TINY_SYSTEM_HEADER #include -#include +#ifdef TINYDRIVERS_DEBUG +# include +#else +# include +#endif TINYORM_BEGIN_COMMON_NAMESPACE @@ -58,15 +62,25 @@ namespace Private constexpr NotNull(U &&u) // NOLINT(google-explicit-constructor) : m_ptr(std::forward(u)) { +#ifdef TINYDRIVERS_DEBUG + Q_ASSERT_X(m_ptr != nullptr, "Drivers::NotNull", + "NotNull pointer can't be nullptr."); +#else if (m_ptr == nullptr) std::terminate(); +#endif } constexpr NotNull(T u) requires (!std::is_same_v) // NOLINT(google-explicit-constructor) : m_ptr(std::move(u)) { +#ifdef TINYDRIVERS_DEBUG + Q_ASSERT_X(m_ptr != nullptr, "Drivers::NotNull", + "NotNull pointer can't be nullptr."); +#else if (m_ptr == nullptr) std::terminate(); +#endif } template U> diff --git a/include/orm/utils/notnull.hpp b/include/orm/utils/notnull.hpp index c8ebb6739..61488f8ba 100644 --- a/include/orm/utils/notnull.hpp +++ b/include/orm/utils/notnull.hpp @@ -7,7 +7,11 @@ TINY_SYSTEM_HEADER #include "orm/macros/commonnamespace.hpp" -#include +#ifdef TINYORM_DEBUG +# include +#else +# include +#endif TINYORM_BEGIN_COMMON_NAMESPACE @@ -58,15 +62,23 @@ namespace Private constexpr NotNull(U &&u) // NOLINT(google-explicit-constructor) : m_ptr(std::forward(u)) { +#ifdef TINYORM_DEBUG + Q_ASSERT_X(m_ptr != nullptr, "NotNull", "NotNull pointer can't be nullptr."); +#else if (m_ptr == nullptr) std::terminate(); +#endif } constexpr NotNull(T u) requires (!std::is_same_v) // NOLINT(google-explicit-constructor) : m_ptr(std::move(u)) { +#ifdef TINYORM_DEBUG + Q_ASSERT_X(m_ptr != nullptr, "NotNull", "NotNull pointer can't be nullptr."); +#else if (m_ptr == nullptr) std::terminate(); +#endif } template U>