summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-09-05 09:52:31 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-09-06 19:24:40 +0200
commitca8fefca858e34bf09a7d691413fb9994e745b22 (patch)
tree52e82d8db64abbefda7b24daaf04c11d62b0bf8b
parent0bd1fc006097e481d8b92ee1c5246ffa1ae9379f (diff)
QCoreApplication::requestPermission: refactor "dead" code
An assert that checks in debug mode is morally equivalent to an assumption/contract in release mode. Rechecking that an assumption is true is pointless (it's true by definition), so the code for the case the check fails is effectively "dead". Right now Q_ASSERT(x) doesn't turn into Q_ASSUME(x) because some compilers still have poor codegen (and basically emit a check, even in release mode). With C++23's [[assume(x)]] we may reconsider that. As soon as we do it, this code is no longer theoretically dead but practically dead. Refactor the code so that the check is done unconditionally, and if it fails, we assert (in debug mode). In release, we protect users from a broken backend (which may cause an endless loop of user code re-requesting the same permission, so it's worth avoiding it). Change-Id: If0e70e7d88a585ce16ec4838ba7be747652d8155 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 203f74a6666..2844da771f1 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -2921,10 +2921,11 @@ void QCoreApplication::requestPermission(const QPermission &requestedPermission,
PermissionReceiver *receiver = new PermissionReceiver(std::move(slotObj), context);
QPermissions::Private::requestPermission(requestedPermission, [=](Qt::PermissionStatus status) {
- Q_ASSERT_X(status != Qt::PermissionStatus::Undetermined, "QPermission",
- "QCoreApplication::requestPermission() should never return Undetermined");
- if (status == Qt::PermissionStatus::Undetermined)
+ if (status == Qt::PermissionStatus::Undetermined) {
+ Q_ASSERT_X(false, "QPermission",
+ "Internal error: requestPermission() should never return Undetermined");
status = Qt::PermissionStatus::Denied;
+ }
if (QCoreApplication::self) {
QPermission permission = requestedPermission;