summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Lemanissier <eric.lemanissier@gmail.com>2017-01-16 12:22:43 +0100
committerEric Lemanissier <eric.lemanissier@gmail.com>2017-02-17 13:57:30 +0000
commitc5e687895dd2eba3106f697b6e92b84683402403 (patch)
treea9658c00cc2fd250b06ceff218e2c6cb65f2c432
parent1d6700171cf41c17983edff285c3658933610523 (diff)
Adapt to the C++ SIC introduced by P0012: noexcept overloading
see 5a1b4832a2 for more detail Task-number: QTBUG-58142 Change-Id: I51851ea9b4fe7b8eeadc452bc3dbb1ea00026d29 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/concurrent/qtconcurrentfunctionwrappers.h84
-rw-r--r--tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro3
-rw-r--r--tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp74
-rw-r--r--tests/auto/concurrent/qtconcurrentrun/qtconcurrentrun.pro3
-rw-r--r--tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp104
5 files changed, 268 insertions, 0 deletions
diff --git a/src/concurrent/qtconcurrentfunctionwrappers.h b/src/concurrent/qtconcurrentfunctionwrappers.h
index a08be69123..111933410b 100644
--- a/src/concurrent/qtconcurrentfunctionwrappers.h
+++ b/src/concurrent/qtconcurrentfunctionwrappers.h
@@ -192,6 +192,32 @@ QtConcurrent::ConstMemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func
return QtConcurrent::ConstMemberFunctionWrapper<T, C>(func);
}
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+template <typename T, typename U>
+QtConcurrent::FunctionWrapper1<T, U> createFunctionWrapper(T (*func)(U) noexcept)
+{
+ return QtConcurrent::FunctionWrapper1<T, U>(func);
+}
+
+template <typename T, typename C>
+QtConcurrent::MemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func)() noexcept)
+{
+ return QtConcurrent::MemberFunctionWrapper<T, C>(func);
+}
+
+template <typename T, typename C, typename U>
+QtConcurrent::MemberFunctionWrapper1<T, C, U> createFunctionWrapper(T (C::*func)(U) noexcept)
+{
+ return QtConcurrent::MemberFunctionWrapper1<T, C, U>(func);
+}
+
+template <typename T, typename C>
+QtConcurrent::ConstMemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func)() const noexcept)
+{
+ return QtConcurrent::ConstMemberFunctionWrapper<T, C>(func);
+}
+#endif
+
struct PushBackWrapper
{
typedef void result_type;
@@ -231,6 +257,20 @@ struct ReduceResultType<T(C::*)(U)>
typedef C ResultType;
};
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+template <class U, class V>
+struct ReduceResultType<void(*)(U&,V) noexcept>
+{
+ typedef U ResultType;
+};
+
+template <class T, class C, class U>
+struct ReduceResultType<T(C::*)(U) noexcept>
+{
+ typedef C ResultType;
+};
+#endif
+
template <class InputSequence, class MapFunctor>
struct MapResultType
{
@@ -249,6 +289,20 @@ struct MapResultType<void, T(C::*)() const>
typedef T ResultType;
};
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+template <class U, class V>
+struct MapResultType<void, U (*)(V) noexcept>
+{
+ typedef U ResultType;
+};
+
+template <class T, class C>
+struct MapResultType<void, T(C::*)() const noexcept>
+{
+ typedef T ResultType;
+};
+#endif
+
#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
template <template <typename> class InputSequence, typename MapFunctor, typename T>
@@ -269,6 +323,21 @@ struct MapResultType<InputSequence<T>, U(C::*)() const>
typedef InputSequence<U> ResultType;
};
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+
+template <template <typename> class InputSequence, class T, class U, class V>
+struct MapResultType<InputSequence<T>, U (*)(V) noexcept>
+{
+ typedef InputSequence<U> ResultType;
+};
+
+template <template <typename> class InputSequence, class T, class U, class C>
+struct MapResultType<InputSequence<T>, U(C::*)() const noexcept>
+{
+ typedef InputSequence<U> ResultType;
+};
+#endif
+
#endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER
template <class MapFunctor>
@@ -289,6 +358,21 @@ struct MapResultType<QStringList, U(C::*)() const>
typedef QList<U> ResultType;
};
+#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
+
+template <class U, class V>
+struct MapResultType<QStringList, U (*)(V) noexcept>
+{
+ typedef QList<U> ResultType;
+};
+
+template <class U, class C>
+struct MapResultType<QStringList, U(C::*)() const noexcept>
+{
+ typedef QList<U> ResultType;
+};
+#endif
+
} // namespace QtPrivate.
#endif //Q_QDOC
diff --git a/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro b/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro
index 3af207ae5a..fd8fd0a74a 100644
--- a/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro
+++ b/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro
@@ -3,3 +3,6 @@ TARGET = tst_qtconcurrentmap
QT = core testlib concurrent
SOURCES = tst_qtconcurrentmap.cpp
DEFINES += QT_STRICT_ITERATORS
+
+# Force C++17 if available
+contains(QT_CONFIG, c++1z): CONFIG += c++1z
diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
index 25ac952396..96656a6dff 100644
--- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
+++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
@@ -48,6 +48,7 @@ private slots:
void blocking_mappedReduced();
void assignResult();
void functionOverloads();
+ void noExceptFunctionOverloads();
#ifndef QT_NO_EXCEPTIONS
void exceptions();
#endif
@@ -2025,6 +2026,16 @@ int fn(int &i)
return i;
}
+int fnConstNoExcept(const int &i) Q_DECL_NOTHROW
+{
+ return i;
+}
+
+int fnNoExcept(int &i) Q_DECL_NOTHROW
+{
+ return i;
+}
+
QString changeTypeConst(const int &)
{
return QString();
@@ -2035,6 +2046,16 @@ QString changeType(int &)
return QString();
}
+QString changeTypeConstNoExcept(const int &) Q_DECL_NOTHROW
+{
+ return QString();
+}
+
+QString changeTypeNoExcept(int &) Q_DECL_NOTHROW
+{
+ return QString();
+}
+
int changeTypeQStringListConst(const QStringList &)
{
return 0;
@@ -2045,6 +2066,16 @@ int changeTypeQStringList(QStringList &)
return 0;
}
+int changeTypeQStringListConstNoExcept(const QStringList &) Q_DECL_NOTHROW
+{
+ return 0;
+}
+
+int changeTypeQStringListNoExcept(QStringList &) Q_DECL_NOTHROW
+{
+ return 0;
+}
+
class MemFnTester
{
public:
@@ -2069,6 +2100,26 @@ public:
{
return QString();
}
+
+ MemFnTester fnNoExcept() Q_DECL_NOTHROW
+ {
+ return MemFnTester();
+ }
+
+ MemFnTester fnConstNoExcept() const Q_DECL_NOTHROW
+ {
+ return MemFnTester();
+ }
+
+ QString changeTypeNoExcept() Q_DECL_NOTHROW
+ {
+ return QString();
+ }
+
+ QString changeTypeConstNoExcept() const Q_DECL_NOTHROW
+ {
+ return QString();
+ }
};
Q_DECLARE_METATYPE(QVector<MemFnTester>);
@@ -2097,6 +2148,29 @@ void tst_QtConcurrentMap::functionOverloads()
QtConcurrent::blockingMapped<QList<QString> >(constMemFnTesterList, &MemFnTester::changeTypeConst);
}
+void tst_QtConcurrentMap::noExceptFunctionOverloads()
+{
+ QList<int> intList;
+ const QList<int> constIntList;
+ QList<MemFnTester> classList;
+ const QList<MemFnTester> constMemFnTesterList;
+
+ QtConcurrent::mapped(intList, fnConstNoExcept);
+ QtConcurrent::mapped(constIntList, fnConstNoExcept);
+ QtConcurrent::mapped(classList, &MemFnTester::fnConstNoExcept);
+ QtConcurrent::mapped(constMemFnTesterList, &MemFnTester::fnConstNoExcept);
+
+ QtConcurrent::blockingMapped<QVector<int> >(intList, fnConstNoExcept);
+ QtConcurrent::blockingMapped<QVector<int> >(constIntList, fnConstNoExcept);
+ QtConcurrent::blockingMapped<QVector<MemFnTester> >(classList, &MemFnTester::fnConstNoExcept);
+ QtConcurrent::blockingMapped<QVector<MemFnTester> >(constMemFnTesterList, &MemFnTester::fnConstNoExcept);
+
+ QtConcurrent::blockingMapped<QList<QString> >(intList, changeTypeConstNoExcept);
+ QtConcurrent::blockingMapped<QList<QString> >(constIntList, changeTypeConstNoExcept);
+ QtConcurrent::blockingMapped<QList<QString> >(classList, &MemFnTester::changeTypeConstNoExcept);
+ QtConcurrent::blockingMapped<QList<QString> >(constMemFnTesterList, &MemFnTester::changeTypeConstNoExcept);
+}
+
QAtomicInt currentInstanceCount;
QAtomicInt peakInstanceCount;
class InstanceCounter
diff --git a/tests/auto/concurrent/qtconcurrentrun/qtconcurrentrun.pro b/tests/auto/concurrent/qtconcurrentrun/qtconcurrentrun.pro
index f60462f9ed..44891b7ba5 100644
--- a/tests/auto/concurrent/qtconcurrentrun/qtconcurrentrun.pro
+++ b/tests/auto/concurrent/qtconcurrentrun/qtconcurrentrun.pro
@@ -2,3 +2,6 @@ CONFIG += testcase
TARGET = tst_qtconcurrentrun
QT = core testlib concurrent
SOURCES = tst_qtconcurrentrun.cpp
+
+# Force C++17 if available
+contains(QT_CONFIG, c++1z): CONFIG += c++1z
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
index bd53aa69fe..4e3668d72e 100644
--- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
+++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
@@ -123,6 +123,28 @@ public:
int operator()(int in) const { return in; }
};
+class ANoExcept
+{
+public:
+ int member0() Q_DECL_NOTHROW { return 10; }
+ int member1(int in) Q_DECL_NOTHROW { return in; }
+
+ typedef int result_type;
+ int operator()() Q_DECL_NOTHROW { return 10; }
+ int operator()(int in) Q_DECL_NOTHROW { return in; }
+};
+
+class AConstNoExcept
+{
+public:
+ int member0() const Q_DECL_NOTHROW { return 10; }
+ int member1(int in) const Q_DECL_NOTHROW { return in; }
+
+ typedef int result_type;
+ int operator()() const Q_DECL_NOTHROW { return 10; }
+ int operator()(int in) const Q_DECL_NOTHROW { return in; }
+};
+
void tst_QtConcurrentRun::returnValue()
{
QThreadPool pool;
@@ -214,6 +236,88 @@ void tst_QtConcurrentRun::returnValue()
QCOMPARE(f.result(), 20);
f = run(&pool, &aConst, 20);
QCOMPARE(f.result(), 20);
+
+ ANoExcept aNoExcept;
+ f = run(&aNoExcept, &ANoExcept::member0);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, &aNoExcept, &ANoExcept::member0);
+ QCOMPARE(f.result(), 10);
+
+ f = run(&aNoExcept, &ANoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, &aNoExcept, &ANoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+
+ f = run(aNoExcept, &ANoExcept::member0);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, aNoExcept, &ANoExcept::member0);
+ QCOMPARE(f.result(), 10);
+
+ f = run(aNoExcept, &ANoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, aNoExcept, &ANoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+
+ f = run(aNoExcept);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, aNoExcept);
+ QCOMPARE(f.result(), 10);
+
+ f = run(&aNoExcept);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, &aNoExcept);
+ QCOMPARE(f.result(), 10);
+
+ f = run(aNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, aNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+
+ f = run(&aNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, &aNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+
+ const AConstNoExcept aConstNoExcept = AConstNoExcept();
+ f = run(&aConstNoExcept, &AConstNoExcept::member0);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, &aConstNoExcept, &AConstNoExcept::member0);
+ QCOMPARE(f.result(), 10);
+
+ f = run(&aConstNoExcept, &AConstNoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, &aConstNoExcept, &AConstNoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+
+ f = run(aConstNoExcept, &AConstNoExcept::member0);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, aConstNoExcept, &AConstNoExcept::member0);
+ QCOMPARE(f.result(), 10);
+
+ f = run(aConstNoExcept, &AConstNoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, aConstNoExcept, &AConstNoExcept::member1, 20);
+ QCOMPARE(f.result(), 20);
+
+ f = run(aConstNoExcept);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, aConstNoExcept);
+ QCOMPARE(f.result(), 10);
+
+ f = run(&aConstNoExcept);
+ QCOMPARE(f.result(), 10);
+ f = run(&pool, &aConstNoExcept);
+ QCOMPARE(f.result(), 10);
+
+ f = run(aConstNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, aConstNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+
+ f = run(&aConstNoExcept, 20);
+ QCOMPARE(f.result(), 20);
+ f = run(&pool, &aConstNoExcept, 20);
+ QCOMPARE(f.result(), 20);
}
struct TestClass