diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-27 17:00:41 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-28 07:45:22 +0200 |
commit | 1c5c1df43e2be10c46c13461888b012c89938150 (patch) | |
tree | ff2ca1cf2bbbf15f6863eafead47e69f8ed32f8b /src/corelib/kernel | |
parent | 9958edba41ac49097a54e0872c3c4934d2dd81f9 (diff) | |
download | qtbase-1c5c1df43e2be10c46c13461888b012c89938150.tar.gz |
Add a helper for better error messages when functor is incompatible
Amends 207aae5560aa2865ec55ddb9ecbb50048060c0c0 to make it easy to
create human-friendly error messages. Since the functor-accepting member
functions are not removed from the API, the first compile error will be
that there is no suitable overload of the makeSlotObject helper, which.
With the assert helper, the first error message is easier to understand.
Change-Id: I4878ec35a44ddfa5dc9d9e358d81c3fd40389c0c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.h | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qobjectdefs_impl.h | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index 2514c7630b..ae01cdee9a 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -126,6 +126,7 @@ public: Functor &&func) { using Prototype = void(*)(QPermission); + QtPrivate::AssertCompatibleFunctions<Prototype, Functor>(); requestPermission(permission, QtPrivate::makeSlotObject<Prototype>(std::forward<Functor>(func)), receiver); diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index e8b9b4a209..721193fe91 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -512,6 +512,21 @@ namespace QtPrivate { ActualArguments, void>(std::forward<Functor>(func)); } } + + template<typename Prototype, typename Functor, typename = void> + struct AreFunctionsCompatible : std::false_type {}; + template<typename Prototype, typename Functor> + struct AreFunctionsCompatible<Prototype, Functor, std::enable_if_t< + std::is_same_v<decltype(QtPrivate::makeSlotObject<Prototype>(std::forward<Functor>(std::declval<Functor>()))), + QtPrivate::QSlotObjectBase *>> + > : std::true_type {}; + + template<typename Prototype, typename Functor> + inline constexpr bool AssertCompatibleFunctions() { + static_assert(AreFunctionsCompatible<Prototype, Functor>::value, + "Functor is not compatible with expected prototype!"); + return true; + } } QT_END_NAMESPACE |