diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-08-22 18:48:48 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-09-01 03:30:50 +0200 |
commit | d027b0c8162ac888de233cf3a41e3254ba2d7cc8 (patch) | |
tree | 3a4606efd0b74960f2339a91262ddfb6e7f9cc1d /src | |
parent | 875f988af5d9df6c85269959414014d6ef1417ad (diff) |
Constrain QCoreApplication::requestPermission to compatible functors
The 6.5 versions of the overload not taking a context/receiver object
were constrained by requiring a functor to be free function or lambda.
207aae5560aa2865ec55ddb9ecbb50048060c0c0 removed that constraint, which
might be source incomaptible if wrapper functions in user code forward
the constraint using Expression SFINAE. Those wrappers would no longer
be removed from the overload set based on the same criteria as the
function they wrap.
We can't constrain the new functions based on the same predicate as
before, as after the simplification we have only one overload with, and
one without context object. But we can still remove overloads for
incompatible functors.
Add the respective scenario to the QPermission test as a compile-time
test.
Found during 6.6 header review.
Pick-to: 6.6
Change-Id: Id21391b4a6b78a29de2f8fa04374f4262e5fafa7
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index eb34c9aa9b..227b17ad83 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -61,6 +61,10 @@ class Q_CORE_EXPORT QCoreApplication Q_DECLARE_PRIVATE(QCoreApplication) friend class QEventLoopLocker; +#if QT_CONFIG(permissions) + using RequestPermissionPrototype = void(*)(QPermission); +#endif + public: enum { ApplicationFlags = QT_VERSION }; @@ -124,21 +128,25 @@ public: # else // requestPermission with context or receiver object; need to require here that receiver is the // right type to avoid ambiguity with the private implementation function. - template <typename Functor> + template <typename Functor, + std::enable_if_t< + QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value, + bool> = true> void requestPermission(const QPermission &permission, const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver, Functor &&func) { - using Prototype = void(*)(QPermission); - QtPrivate::AssertCompatibleFunctions<Prototype, Functor>(); requestPermission(permission, - QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)), + QtPrivate::makeCallableObject<RequestPermissionPrototype>(std::forward<Functor>(func)), receiver); } # endif // Q_QDOC // requestPermission to a functor or function pointer (without context) - template <typename Functor> + template <typename Functor, + std::enable_if_t< + QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value, + bool> = true> void requestPermission(const QPermission &permission, Functor &&func) { requestPermission(permission, nullptr, std::forward<Functor>(func)); |