diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-01-25 17:40:24 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-31 16:17:55 +0100 |
commit | 2bf186a2e598a4bccdc4979085e8e4d963a3819d (patch) | |
tree | dee756d5a8b271bbd5950ea4ac1d7ca638054348 | |
parent | 3855233dab82946ba50ddd90ce86df035998da8e (diff) |
Allow function types to be registered without workarounds
Commit 4b8ceb41aed352f10d36db5284453f425dbc5f3f added the requirement
that pointed-to types need to be registered when registering pointer
types. Unfortunately, the implementation also affects function pointer
types.
This change whitelists 0, 1, 2 and 3 argument functions as not deriving
from QObject, forgoing the need to workaround details of the type
registration implementation when registering those function pointer
types.
Change-Id: I4d855e9d70a8179a6e31b84623ad5bf063e0d6d8
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
-rw-r--r-- | src/corelib/io/qtextstream.h | 6 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 6 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 13 | ||||
-rw-r--r-- | tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp | 5 | ||||
-rw-r--r-- | tests/benchmarks/corelib/tools/qstring/main.cpp | 15 |
5 files changed, 19 insertions, 26 deletions
diff --git a/src/corelib/io/qtextstream.h b/src/corelib/io/qtextstream.h index e3686e10ef..3e1d0faa25 100644 --- a/src/corelib/io/qtextstream.h +++ b/src/corelib/io/qtextstream.h @@ -208,12 +208,6 @@ typedef void (QTextStream::*QTSMFI)(int); // manipulator w/int argument typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument -namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<QTextStreamFunction> { - enum { Value = false }; -}; -} - class Q_CORE_EXPORT QTextStreamManipulator { public: diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index fd5c5f30dd..0ea9d26394 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -365,6 +365,12 @@ namespace QtPrivate { Q_STATIC_ASSERT_X(sizeof(T), "Type argument of Q_DECLARE_METATYPE(T*) must be fully defined"); enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(yes_type) }; }; + + // Function pointers don't derive from QObject + template <class Result> struct IsPointerToTypeDerivedFromQObject<Result(*)()> { enum { Value = false }; }; + template <class Result, class Arg0> struct IsPointerToTypeDerivedFromQObject<Result(*)(Arg0)> { enum { Value = false }; }; + template <class Result, class Arg0, class Arg1> struct IsPointerToTypeDerivedFromQObject<Result(*)(Arg0, Arg1)> { enum { Value = false }; }; + template <class Result, class Arg0, class Arg1, class Arg2> struct IsPointerToTypeDerivedFromQObject<Result(*)(Arg0, Arg1, Arg2)> { enum { Value = false }; }; } template <typename T> diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 82e59cef76..be13b39e7e 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -931,5 +931,18 @@ void tst_QMetaType::automaticTemplateRegistration() } } +// Compile-time test, it should be possible to register function pointer types +class Undefined; + +typedef Undefined (*UndefinedFunction0)(); +typedef Undefined (*UndefinedFunction1)(Undefined); +typedef Undefined (*UndefinedFunction2)(Undefined, Undefined); +typedef Undefined (*UndefinedFunction3)(Undefined, Undefined, Undefined); + +Q_DECLARE_METATYPE(UndefinedFunction0); +Q_DECLARE_METATYPE(UndefinedFunction1); +Q_DECLARE_METATYPE(UndefinedFunction2); +Q_DECLARE_METATYPE(UndefinedFunction3); + QTEST_MAIN(tst_QMetaType) #include "tst_qmetatype.moc" diff --git a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index e53582f178..71a70384fc 100644 --- a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp +++ b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp @@ -99,11 +99,6 @@ struct AbstractTester Q_DECLARE_METATYPE(AbstractTester *) typedef void (*TestFunction)(QObject*); -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<TestFunction> { - enum { Value = false }; -}; -} QT_END_NAMESPACE Q_DECLARE_METATYPE(TestFunction) template <typename T> diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp index ca72a9b013..9d5c43c290 100644 --- a/tests/benchmarks/corelib/tools/qstring/main.cpp +++ b/tests/benchmarks/corelib/tools/qstring/main.cpp @@ -1298,11 +1298,6 @@ static int ucstrncmp_ssse3_aligning2(const ushort *a, const ushort *b, int len) #endif typedef int (* UcstrncmpFunction)(const ushort *, const ushort *, int); -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<UcstrncmpFunction> { - enum { Value = false }; -}; -} QT_END_NAMESPACE Q_DECLARE_METATYPE(UcstrncmpFunction) void tst_QString::ucstrncmp_data() const @@ -1462,11 +1457,6 @@ void tst_QString::fromLatin1() const } typedef void (* FromLatin1Function)(ushort *, const char *, int); -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<FromLatin1Function> { - enum { Value = false }; -}; -} QT_END_NAMESPACE Q_DECLARE_METATYPE(FromLatin1Function) void fromLatin1_regular(ushort *dst, const char *str, int size) @@ -1917,11 +1907,6 @@ void tst_QString::fromLatin1Alternatives() const } typedef int (* FromUtf8Function)(ushort *, const char *, int); -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<FromUtf8Function> { - enum { Value = false }; -}; -} QT_END_NAMESPACE Q_DECLARE_METATYPE(FromUtf8Function) extern QTextCodec::ConverterState *state; |