From 8aacf83a76aa8d4896bbfb1b3a6e81fa697ae4e6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 31 May 2022 18:27:41 +0200 Subject: [PATCH] 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 Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 2cbe9ee5597..30d2a294dc8 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -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)