Fix QScopedPointerarray default constructor
authorOlivier Goffart <olivier.goffart@nokia.com>
Tue, 5 Jul 2011 12:06:01 +0000 (14:06 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 5 Jul 2011 15:03:32 +0000 (17:03 +0200)
Since the compiler cannod find the template argument if there is no
argument passed to the constructor, this effectively means there is
no default constructor.

Add a default constructor

Task-number: QTBUG-20256
Change-Id: I310d5e1f3f94a8fe69fd3a5c46f2f51bca60facd
Reviewed-on: http://codereview.qt.nokia.com/1165
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
src/corelib/tools/qscopedpointer.h
tests/auto/qscopedpointer/tst_qscopedpointer.cpp

index b15bcac..a24f62e 100644 (file)
@@ -208,8 +208,10 @@ template <typename T, typename Cleanup = QScopedPointerArrayDeleter<T> >
 class QScopedArrayPointer : public QScopedPointer<T, Cleanup>
 {
 public:
+    inline QScopedArrayPointer() : QScopedPointer<T, Cleanup>(0) {}
+
     template <typename D>
-    explicit inline QScopedArrayPointer(D *p = 0, typename QtPrivate::QScopedArrayEnsureSameType<T,D>::Type = 0)
+    explicit inline QScopedArrayPointer(D *p, typename QtPrivate::QScopedArrayEnsureSameType<T,D>::Type = 0)
         : QScopedPointer<T, Cleanup>(p)
     {
     }
index 1a6f944..06c0ecb 100644 (file)
@@ -72,6 +72,7 @@ private Q_SLOTS:
     void isNullSignature();
     void objectSize();
     void comparison();
+    void array();
     // TODO instanciate on const object
 };
 
@@ -437,5 +438,26 @@ void tst_QScopedPointer::comparison()
     QCOMPARE( int(RefCounted::instanceCount), 0 );
 }
 
+void tst_QScopedPointer::array()
+{
+    int instCount = RefCounted::instanceCount;
+    {
+        QScopedArrayPointer<RefCounted> array;
+        array.reset(new RefCounted[42]);
+        QCOMPARE(instCount + 42, int(RefCounted::instanceCount));
+    }
+    QCOMPARE(instCount, int(RefCounted::instanceCount));
+    {
+        QScopedArrayPointer<RefCounted> array(new RefCounted[42]);
+        QCOMPARE(instCount + 42, int(RefCounted::instanceCount));
+        array.reset(new RefCounted[28]);
+        QCOMPARE(instCount + 28, int(RefCounted::instanceCount));
+        array.reset(0);
+        QCOMPARE(instCount, int(RefCounted::instanceCount));
+    }
+    QCOMPARE(instCount, int(RefCounted::instanceCount));
+}
+
+
 QTEST_MAIN(tst_QScopedPointer)
 #include "tst_qscopedpointer.moc"