aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/array.h5
-rw-r--r--test/common/array.h5
2 files changed, 8 insertions, 2 deletions
diff --git a/common/array.h b/common/array.h
index 1645db05b1..d4dac35866 100644
--- a/common/array.h
+++ b/common/array.h
@@ -63,9 +63,10 @@ public:
* Constructs an array with `count` default-inserted instances of T. No
* copies are made.
*/
- explicit Array(size_type count) : _size(0) {
+ explicit Array(size_type count) : _size(count) {
allocCapacity(count);
- resize(count);
+ for (size_type i = 0; i < count; ++i)
+ new ((void *)&_storage[i]) T();
}
/**
diff --git a/test/common/array.h b/test/common/array.h
index 45be99371f..e0a6438d52 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
#include "common/array.h"
+#include "common/noncopyable.h"
#include "common/str.h"
class ArrayTestSuite : public CxxTest::TestSuite
@@ -315,6 +316,10 @@ class ArrayTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(array.size(), 10U);
TS_ASSERT_EQUALS(array[0], 0);
TS_ASSERT_EQUALS(array[9], 0);
+
+ // This will fail at compile time if it is not possible to construct an
+ // array without copy-construction
+ Common::Array<Common::NonCopyable> nonCopyable(1);
}
void test_array_constructor_count_copy_value() {