Build fix for auto-registration of Container<void*>

IteratorOwner pointer specialization was failing for void* because of
an invalid function overload.

Change-Id: I80355ddd2b871c1fa2fa5bf5a4ed8bc7768fc3c9
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Jędrzej Nowacki 2014-03-06 14:54:19 +01:00 committed by The Qt Project
parent 969da85c2b
commit 33fae8b147
2 changed files with 17 additions and 2 deletions

View File

@ -821,7 +821,14 @@ struct IteratorOwner
template<typename value_type>
struct IteratorOwner<const value_type*>
{
static void assign(void **ptr, const value_type *iterator )
private:
// We need to disable typed overloads of assign() and getData() if the value_type
// is void* to avoid overloads conflicts. We do it by injecting unaccessible Dummy
// type as part of the overload signature.
struct Dummy {};
typedef typename QtPrivate::if_<QtPrivate::is_same<value_type, void*>::value, Dummy, value_type>::type value_type_OR_Dummy;
public:
static void assign(void **ptr, const value_type_OR_Dummy *iterator )
{
*ptr = const_cast<value_type*>(iterator);
}
@ -846,7 +853,7 @@ struct IteratorOwner<const value_type*>
return *iterator;
}
static const void *getData(const value_type *it)
static const void *getData(const value_type_OR_Dummy *it)
{
return it;
}

View File

@ -1341,6 +1341,8 @@ static QByteArray createTypeName(const char *begin, const char *va)
}
#endif
Q_DECLARE_METATYPE(const void*)
void tst_QMetaType::automaticTemplateRegistration()
{
#define TEST_SEQUENTIAL_CONTAINER(CONTAINER, VALUE_TYPE) \
@ -1577,6 +1579,12 @@ void tst_QMetaType::automaticTemplateRegistration()
)
CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QVariantList> > >)
CREATE_AND_VERIFY_CONTAINER(QVector, void*)
CREATE_AND_VERIFY_CONTAINER(QVector, const void*)
CREATE_AND_VERIFY_CONTAINER(QList, void*)
CREATE_AND_VERIFY_CONTAINER(QPair, void*, void*)
CREATE_AND_VERIFY_CONTAINER(QHash, void*, void*)
CREATE_AND_VERIFY_CONTAINER(QHash, const void*, const void*)
#endif // Q_COMPILER_VARIADIC_MACROS