summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobjectdefs_impl.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-01-10 15:30:42 -0800
committerThiago Macieira <thiago.macieira@intel.com>2017-01-14 03:24:30 +0000
commit5a1b4832a2704e7fb386d6b4c73dab85facdc40b (patch)
tree9b5413ec35eeb7baf92d1d9211b67e83b0ad6cdd /src/corelib/kernel/qobjectdefs_impl.h
parent635d0ae00717b9ba53a8e007e50fac0d2721ca35 (diff)
Adapt to the C++ SIC introduced by P0021: noexcept overloading
C++17 adopts P0021R1[1], which makes noexcept be part of the function pointer's type and thus be overloadable. It contains some provisions for allowing a noexcept function pointer to cast implicitly to a non- noexcept function pointer, but that fails in the presence of templates and additional overloads that could match the type in question. Fortunately, the paper proposed a test macro, so we can change our sources now and be compatible with both C++14 and C++17 rules. This first failed with Clang 4.0 trunk. This source incompatibility is not our fault, it's the language's doing. [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html Task-number: QTBUG-58054 Change-Id: I2bc52f3c7a574209b213fffd14988cf0b875be63 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qobjectdefs_impl.h')
-rw-r--r--src/corelib/kernel/qobjectdefs_impl.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h
index 79c9c8303e..1768e8ccc6 100644
--- a/src/corelib/kernel/qobjectdefs_impl.h
+++ b/src/corelib/kernel/qobjectdefs_impl.h
@@ -149,6 +149,20 @@ namespace QtPrivate {
(o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]);
}
};
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+ template <int... II, typename... SignalArgs, typename R, typename... SlotArgs, typename SlotRet, class Obj>
+ struct FunctorCall<IndexesList<II...>, List<SignalArgs...>, R, SlotRet (Obj::*)(SlotArgs...) noexcept> {
+ static void call(SlotRet (Obj::*f)(SlotArgs...) noexcept, Obj *o, void **arg) {
+ (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]);
+ }
+ };
+ template <int... II, typename... SignalArgs, typename R, typename... SlotArgs, typename SlotRet, class Obj>
+ struct FunctorCall<IndexesList<II...>, List<SignalArgs...>, R, SlotRet (Obj::*)(SlotArgs...) const noexcept> {
+ static void call(SlotRet (Obj::*f)(SlotArgs...) const noexcept, Obj *o, void **arg) {
+ (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]);
+ }
+ };
+#endif
template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...)>
{
@@ -187,6 +201,47 @@ namespace QtPrivate {
}
};
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+ template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...) noexcept>
+ {
+ typedef Obj Object;
+ typedef List<Args...> Arguments;
+ typedef Ret ReturnType;
+ typedef Ret (Obj::*Function) (Args...) noexcept;
+ template <class Base> struct ChangeClass { typedef Ret (Base:: *Type)(Args...) noexcept; };
+ enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = true};
+ template <typename SignalArgs, typename R>
+ static void call(Function f, Obj *o, void **arg) {
+ FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, o, arg);
+ }
+ };
+ template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...) const noexcept>
+ {
+ typedef Obj Object;
+ typedef List<Args...> Arguments;
+ typedef Ret ReturnType;
+ typedef Ret (Obj::*Function) (Args...) const noexcept;
+ template <class Base> struct ChangeClass { typedef Ret (Base:: *Type)(Args...) const noexcept; };
+ enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = true};
+ template <typename SignalArgs, typename R>
+ static void call(Function f, Obj *o, void **arg) {
+ FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, o, arg);
+ }
+ };
+
+ template<typename Ret, typename... Args> struct FunctionPointer<Ret (*) (Args...) noexcept>
+ {
+ typedef List<Args...> Arguments;
+ typedef Ret ReturnType;
+ typedef Ret (*Function) (Args...) noexcept;
+ enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = false};
+ template <typename SignalArgs, typename R>
+ static void call(Function f, void *, void **arg) {
+ FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, arg);
+ }
+ };
+#endif
+
template<typename Function, int N> struct Functor
{
template <typename SignalArgs, typename R>