Make Q_ASSUME() an expression (was: statement)

Like Q_ASSERT(), which was fixed for 5.10, it's also useful if
Q_ASSUME() expands to an expression instead of a statement. This way,
it's usable in more contexts, esp. the comma operator.

[ChangeLog][QtCore][QtGlobal] Q_ASSUME() now expands to an expression
(was: statement).

Change-Id: I33dc3d1551a1b7454aa9587b9c33dfa2e3d2b09c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-05-31 18:27:41 +02:00
parent d631e581c0
commit 8aacf83a76

View File

@ -1132,11 +1132,10 @@
} while (false)
#define Q_ASSUME(Expr) \
do {\
const bool valueOfExpression = Expr;\
[] (bool valueOfExpression) {\
Q_ASSERT_X(valueOfExpression, "Q_ASSUME()", "Assumption in Q_ASSUME(\"" #Expr "\") was not correct");\
Q_ASSUME_IMPL(valueOfExpression);\
} while (false)
}(Expr)
#if defined(__cplusplus)
#if __has_cpp_attribute(clang::fallthrough)