Make sure all containers compile in strict-iterator mode

Unit-test this by making the QList, QVector, QHash and QMap unit tests
be duplicated under strict-iterator mode. There's no test for
QLinkedList.

The tst_Collections test does not compile under strict-iterator
mode. It generated over 15000 errors when I tried.

The strict iterators required a small change: the difference_type
typedef needs to match the operators that get distances
(operator-(iterator)) and move the iterator around (+, -, +=, -=, etc.).

Task-number: QTBUG-29608
Change-Id: I834873934c51d0f139a994cd395818da4ec997e2
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Jason McDonald <macadder1@gmail.com>
bb10
Thiago Macieira 2013-02-07 13:56:57 -08:00 committed by The Qt Project
parent de5ae6917c
commit 1c63909ad8
16 changed files with 36 additions and 18 deletions

View File

@ -135,7 +135,7 @@ struct QTypedArrayData
public:
T *i;
typedef std::random_access_iterator_tag iterator_category;
typedef qptrdiff difference_type;
typedef int difference_type;
typedef T value_type;
typedef T *pointer;
typedef T &reference;
@ -169,7 +169,7 @@ struct QTypedArrayData
public:
const T *i;
typedef std::random_access_iterator_tag iterator_category;
typedef qptrdiff difference_type;
typedef int difference_type;
typedef T value_type;
typedef const T *pointer;
typedef const T &reference;

View File

@ -122,7 +122,7 @@ struct QPodArrayOps
Q_ASSERT(b >= this->begin() && b < this->end());
Q_ASSERT(e > this->begin() && e < this->end());
::memmove(b, e, (this->end() - e) * sizeof(T));
::memmove(b, e, (static_cast<T *>(this->end()) - e) * sizeof(T));
this->size -= (e - b);
}
};

View File

@ -1,6 +1,6 @@
TARGET = tst_qarraydata
SOURCES += tst_qarraydata.cpp
HEADERS += simplevector.h
SOURCES += $$PWD/tst_qarraydata.cpp
HEADERS += $$PWD/simplevector.h
QT = core testlib
CONFIG += testcase parallel_test
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -269,9 +269,9 @@ public:
if (first == last)
return;
T *const begin = d->begin();
T *const where = begin + position;
const T *const end = begin + d->size;
const iterator begin = d->begin();
const iterator where = begin + position;
const iterator end = begin + d->size;
if (d.needsDetach()
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
@ -290,8 +290,8 @@ public:
if ((first >= where && first < end)
|| (last > where && last <= end)) {
// Copy overlapping data first and only then shuffle it into place
T *start = d->begin() + position;
T *middle = d->end();
iterator start = d->begin() + position;
iterator middle = d->end();
d->copyAppend(first, last);
std::rotate(start, middle, d->end());

View File

@ -1559,7 +1559,7 @@ void tst_QArrayData::literals()
#endif
QVERIFY(v.isSharable());
QCOMPARE((void*)(v.constBegin() + v.size()), (void*)v.constEnd());
QCOMPARE((void*)(const char*)(v.constBegin() + v.size()), (void*)(const char*)v.constEnd());
for (int i = 0; i < 10; ++i)
QCOMPARE(const_(v)[i], char('A' + i));

View File

@ -0,0 +1,3 @@
include(../qarraydata/qarraydata.pro)
TARGET = tst_qarraydata_strictiterators
DEFINES += QT_STRICT_ITERATORS=1 tst_QArrayData=tst_QArrayData_StrictIterators

View File

@ -1,5 +1,5 @@
CONFIG += testcase parallel_test
TARGET = tst_qhash
QT = core testlib
SOURCES = tst_qhash.cpp
SOURCES = $$PWD/tst_qhash.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -0,0 +1,3 @@
include(../qhash/qhash.pro)
TARGET = tst_qhash_strictiterators
DEFINES += QT_STRICT_ITERATORS tst_QHash=tst_QHash_StrictIterators

View File

@ -2,5 +2,5 @@ CONFIG += testcase
CONFIG += parallel_test
TARGET = tst_qlist
QT = core testlib
SOURCES = tst_qlist.cpp
SOURCES = $$PWD/tst_qlist.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -0,0 +1,3 @@
include(../qlist/qlist.pro)
TARGET = tst_qlist_strictiterators
DEFINES += QT_STRICT_ITERATORS tst_QList=tst_QList_StrictIterators

View File

@ -1,5 +1,5 @@
CONFIG += testcase parallel_test
TARGET = tst_qmap
QT = core testlib
SOURCES = tst_qmap.cpp
SOURCES = $$PWD/tst_qmap.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -39,8 +39,6 @@
**
****************************************************************************/
#define QT_STRICT_ITERATORS
#include <qmap.h>
#include <QtTest/QtTest>
#include <QDebug>

View File

@ -0,0 +1,3 @@
include(../qmap/qmap.pro)
TARGET = tst_qmap_strictiterators
DEFINES += QT_STRICT_ITERATORS tst_QMap=tst_QMap_StrictIterators

View File

@ -1,5 +1,5 @@
CONFIG += testcase parallel_test
TARGET = tst_qvector
QT = core testlib
SOURCES = tst_qvector.cpp
SOURCES = $$PWD/tst_qvector.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -0,0 +1,3 @@
include(../qvector/qvector.pro)
TARGET = tst_qvector_strictiterators
DEFINES += QT_STRICT_ITERATORS=1 tst_QVector=tst_QVector_StrictIterators

View File

@ -2,6 +2,7 @@ TEMPLATE=subdirs
SUBDIRS=\
qalgorithms \
qarraydata \
qarraydata_strictiterators \
qbitarray \
qbytearray \
qbytearraylist \
@ -20,11 +21,14 @@ SUBDIRS=\
qexplicitlyshareddatapointer \
qfreelist \
qhash \
qhash_strictiterators \
qline \
qlinkedlist \
qlist \
qlist_strictiterators \
qlocale \
qmap \
qmap_strictiterators \
qmargins \
qmessageauthenticationcode \
qpair \
@ -54,4 +58,5 @@ SUBDIRS=\
qtimezone \
qtimeline \
qvarlengtharray \
qvector
qvector \
qvector_strictiterators