summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-03-11 11:38:17 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-03-11 11:38:17 (GMT)
commit65f5cecdd0343d816d9abb8342bd8b2faecdf3b8 (patch)
treed362d9a545dca4a1c636589767624fccea495cef
parent5eeb8abdf5eb81abf4700190b846bf8236cdcd93 (diff)
parentfbb600a7a92b60b388406fecf2d8a94f0d4f5586 (diff)
downloadQt-65f5cecdd0343d816d9abb8342bd8b2faecdf3b8.zip
Qt-65f5cecdd0343d816d9abb8342bd8b2faecdf3b8.tar.gz
Qt-65f5cecdd0343d816d9abb8342bd8b2faecdf3b8.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-2: QVarLenghtArray: Call constructor when resizing the array for Movable types.
-rw-r--r--src/corelib/tools/qvarlengtharray.h3
-rw-r--r--tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp47
2 files changed, 46 insertions, 4 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 1069b816..aecb66e 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -222,7 +222,6 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a
}
} else {
qMemCopy(ptr, oldPtr, qMin(asize, osize) * sizeof(T));
- s = asize;
}
} else {
ptr = oldPtr;
@@ -233,7 +232,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a
if (QTypeInfo<T>::isComplex) {
while (osize > asize)
(oldPtr+(--osize))->~T();
- if( oldPtr == ptr )
+ if (!QTypeInfo<T>::isStatic)
s = osize;
}
diff --git a/tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp
index 0fcde21..1c43069 100644
--- a/tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -42,6 +42,7 @@
#include <QtTest/QtTest>
#include <qvarlengtharray.h>
+#include <qvariant.h>
const int N = 1;
@@ -61,6 +62,7 @@ private slots:
void removeLast();
void oldTests();
void task214223();
+ void QTBUG6718_resize();
};
int fooCtor = 0;
@@ -71,7 +73,7 @@ struct Foo
int *p;
Foo() { p = new int; ++fooCtor; }
- Foo(const Foo &other) { p = new int; ++fooCtor; }
+ Foo(const Foo &/*other*/) { p = new int; ++fooCtor; }
void operator=(const Foo & /* other */) { }
@@ -244,9 +246,50 @@ void tst_QVarLengthArray::task214223()
// will make the next call to append(const T&) corrupt the memory
// you should get a segfault pretty soon after that :-)
QVarLengthArray<float, 1> d(1);
- for (int i=0; i<30; i++)
+ for (int i=0; i<30; i++)
d.append(i);
}
+void tst_QVarLengthArray::QTBUG6718_resize()
+{
+ //MOVABLE
+ {
+ QVarLengthArray<QVariant,1> values(1);
+ QCOMPARE(values.size(), 1);
+ values[0] = 1;
+ values.resize(2);
+ QCOMPARE(values[1], QVariant());
+ QCOMPARE(values[0], QVariant(1));
+ values[1] = 2;
+ QCOMPARE(values[1], QVariant(2));
+ QCOMPARE(values.size(), 2);
+ }
+
+ //POD
+ {
+ QVarLengthArray<int,1> values(1);
+ QCOMPARE(values.size(), 1);
+ values[0] = 1;
+ values.resize(2);
+ QCOMPARE(values[0], 1);
+ values[1] = 2;
+ QCOMPARE(values[1], 2);
+ QCOMPARE(values.size(), 2);
+ }
+
+ //COMPLEX
+ {
+ QVarLengthArray<QVarLengthArray<QString, 15>,1> values(1);
+ QCOMPARE(values.size(), 1);
+ values[0].resize(10);
+ values.resize(2);
+ QCOMPARE(values[1].size(), 0);
+ QCOMPARE(values[0].size(), 10);
+ values[1].resize(20);
+ QCOMPARE(values[1].size(), 20);
+ QCOMPARE(values.size(), 2);
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QVarLengthArray)
#include "tst_qvarlengtharray.moc"