Q_ASSERT_X: fix build where (where) or (what) were not castable to bool

Amends commit 868645fd3be039e37c96315059ab0b851d022bf4

Code like (qtmultmedia):

    Q_ASSERT_X(QFile::exists(shaderFile), Q_FUNC_INFO,
               QStringLiteral("Shader file %1 does not exist").arg(shaderFile).toLatin1());

Change-Id: Iab02812335384115a689fffd871cd478c7c20046
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2025-02-06 15:16:38 -08:00
parent e4bcd9f1cb
commit 6069933b57

View File

@ -38,10 +38,11 @@ Q_NORETURN
Q_DECL_COLD_FUNCTION
Q_CORE_EXPORT
void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept;
inline bool qt_no_assert_x(bool, const char *, const char *) noexcept { return false; }
#if !defined(Q_ASSERT_X)
# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
# define Q_ASSERT_X(cond, where, what) static_cast<void>(false && (cond) && (where) && (what))
# define Q_ASSERT_X(cond, where, what) static_cast<void>(false && qt_no_assert_x(bool(cond), where, what))
# else
# define Q_ASSERT_X(cond, where, what) ((cond) ? static_cast<void>(0) : qt_assert_x(where, what, __FILE__, __LINE__))
# endif