From 6c19d1c5eaf2417afa6475fdaf470cc4c3896899 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 21 Aug 2020 22:46:33 +0200 Subject: Leave a comment about a usage of a restricted bool trick I'm pretty sure we want to keep supporting statements like bool ok = connect(~~~); that is, statements that do use copy initialization and not direct initialization. As such, QMetaObject::Connection has to keep using the restricted bool trick and cannot be ported over to explicit operator bool. Change-Id: I07a38f7c134686e67b5984aa93fe5cf3201561d7 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qobjectdefs.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib/kernel/qobjectdefs.h') diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index d47c311c18..2013af1695 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -453,6 +453,8 @@ public: #ifdef Q_QDOC operator bool() const; #else + // still using the restricted bool trick here, in order to support + // code using copy-init (e.g. `bool ok = connect(...)`) typedef void *Connection::*RestrictedBool; operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; } #endif -- cgit v1.2.3