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 <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2020-08-21 22:46:33 +02:00
parent 4527b2d165
commit 6c19d1c5ea

View File

@ -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