diff --git a/src/corelib/global/qassert.h b/src/corelib/global/qassert.h index 388932a8f7f..6c04cd8a926 100644 --- a/src/corelib/global/qassert.h +++ b/src/corelib/global/qassert.h @@ -47,6 +47,16 @@ void qt_assert_x(const char *where, const char *what, const char *file, int line # endif #endif +#ifndef Q_PRE +# define Q_PRE(cond) \ + Q_ASSERT(cond) /* for now... */ +#endif + +#ifndef Q_PRE_X +# define Q_PRE_X(cond, what) \ + Q_ASSERT_X(cond, Q_FUNC_INFO, what) /* for now... */ +#endif + Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) noexcept; Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qBadAlloc(); diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 454dd1fdad9..0051d9211e7 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -130,9 +130,9 @@ public: constexpr QStringView(const Char *str, qsizetype len) #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) : m_data(castHelper(str)), - m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)) + m_size((Q_PRE(len >= 0), Q_PRE(str || !len), len)) #else - : m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)), + : m_size((Q_PRE(len >= 0), Q_PRE(str || !len), len)), m_data(castHelper(str)) #endif {} @@ -404,8 +404,8 @@ public: [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); } [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; } - [[nodiscard]] constexpr QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); } - [[nodiscard]] constexpr QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); } + [[nodiscard]] constexpr QChar front() const { return Q_PRE(!empty()), QChar(m_data[0]); } + [[nodiscard]] constexpr QChar back() const { return Q_PRE(!empty()), QChar(m_data[m_size - 1]); } [[nodiscard]] Q_IMPLICIT operator std::u16string_view() const noexcept { return std::u16string_view(m_data, size_t(m_size)); } @@ -441,10 +441,10 @@ private: Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0, [[maybe_unused]] qsizetype n = 1) const { - Q_ASSERT(pos >= 0); - Q_ASSERT(pos <= size()); - Q_ASSERT(n >= 0); - Q_ASSERT(n <= size() - pos); + Q_PRE(pos >= 0); + Q_PRE(pos <= size()); + Q_PRE(n >= 0); + Q_PRE(n <= size() - pos); } constexpr int compare_single_char_helper(int diff) const noexcept