From 307f55129181f67fb99bd9dd38b7017928a0aae1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 16 Jun 2015 11:27:04 +0200 Subject: QMap: use constrained templates instead of static-ifs Avoids warnings about constant expressions in ifs. Task-number: QTBUG-46649 Change-Id: I56adf8e80091330d2e97327df7751e57411fbd70 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/tools/qmap.h | 54 ++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'src/corelib/tools/qmap.h') diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index d92bb5ae60..f4678e4b2f 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef Q_MAP_DEBUG #include @@ -94,6 +95,13 @@ struct Q_CORE_EXPORT QMapNodeBase void setColor(Color c) { if (c == Black) p |= Black; else p &= ~Black; } QMapNodeBase *parent() const { return reinterpret_cast(p & ~Mask); } void setParent(QMapNodeBase *pp) { p = (p & Mask) | quintptr(pp); } + + template + static typename QtPrivate::QEnableIf::isComplex>::Type + callDestructorIfNecessary(T &t) Q_DECL_NOTHROW { Q_UNUSED(t); t.~T(); } // Q_UNUSED: silence MSVC unused 't' warning + template + static typename QtPrivate::QEnableIf::isComplex>::Type + callDestructorIfNecessary(T &) Q_DECL_NOTHROW {} }; template @@ -112,12 +120,26 @@ struct QMapNode : public QMapNodeBase QMapNode *copy(QMapData *d) const; - void destroySubTree(); + void destroySubTree() + { + callDestructorIfNecessary(key); + callDestructorIfNecessary(value); + doDestroySubTree(QtPrivate::integral_constant::isComplex || QTypeInfo::isComplex>()); + } QMapNode *lowerBound(const Key &key); QMapNode *upperBound(const Key &key); private: + void doDestroySubTree(QtPrivate::false_type) {} + void doDestroySubTree(QtPrivate::true_type) + { + if (left) + leftNode()->destroySubTree(); + if (right) + rightNode()->destroySubTree(); + } + QMapNode() Q_DECL_EQ_DELETE; Q_DISABLE_COPY(QMapNode) }; @@ -246,37 +268,11 @@ QMapNode *QMapNode::copy(QMapData *d) const return n; } -#if defined(Q_CC_MSVC) -#pragma warning( push ) -#pragma warning( disable : 4127 ) // conditional expression is constant -#endif - -template -void QMapNode::destroySubTree() -{ - if (QTypeInfo::isComplex) - key.~Key(); - if (QTypeInfo::isComplex) - value.~T(); - if (QTypeInfo::isComplex || QTypeInfo::isComplex) { - if (left) - leftNode()->destroySubTree(); - if (right) - rightNode()->destroySubTree(); - } -} - -#if defined(Q_CC_MSVC) -#pragma warning( pop ) -#endif - template void QMapData::deleteNode(QMapNode *z) { - if (QTypeInfo::isComplex) - z->key.~Key(); - if (QTypeInfo::isComplex) - z->value.~T(); + QMapNodeBase::callDestructorIfNecessary(z->key); + QMapNodeBase::callDestructorIfNecessary(z->value); freeNodeAndRebalance(z); } -- cgit v1.2.3