aboutsummaryrefslogtreecommitdiff
path: root/test/SemaTemplate/example-dynarray.cpp
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2009-05-29 16:43:59 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2009-05-29 16:43:59 +0000
commite47590e17725cd37e84bd959d42ea0505b5f1b0d (patch)
tree12de961591db5452f36d56339d156944c238834f /test/SemaTemplate/example-dynarray.cpp
parent4f54f4e2f1af5850805033d69c5199df068d11e7 (diff)
Fix usage of placement new. Placement new is not actually declared implicitly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72576 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate/example-dynarray.cpp')
-rw-r--r--test/SemaTemplate/example-dynarray.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/test/SemaTemplate/example-dynarray.cpp b/test/SemaTemplate/example-dynarray.cpp
index 51eece9e6f..dd2488fc38 100644
--- a/test/SemaTemplate/example-dynarray.cpp
+++ b/test/SemaTemplate/example-dynarray.cpp
@@ -1,7 +1,15 @@
// RUN: clang-cc -fsyntax-only -verify %s
+#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
+// Placement new requires <new> to be included, but we don't support that yet.
+void* operator new(size_t, void* ptr) throw() {
+ return ptr;
+}
+void operator delete(void*, void*) throw() {
+}
+
template<typename T>
class dynarray {
public:
@@ -11,10 +19,8 @@ public:
Start = (T*)malloc(sizeof(T) * other.size());
Last = End = Start + other.size();
- // FIXME: Use placement new, below
for (unsigned I = 0, N = other.size(); I != N; ++I)
- Start[I] = other[I];
- // new (Start + I) T(other[I]);
+ new (Start + I) T(other[I]);
}
~dynarray() {
@@ -24,11 +30,9 @@ public:
dynarray &operator=(const dynarray &other) {
T* NewStart = (T*)malloc(sizeof(T) * other.size());
- // FIXME: Use placement new, below
for (unsigned I = 0, N = other.size(); I != N; ++I)
- NewStart[I] = other[I];
- // new (Start + I) T(other[I]);
-
+ new (Start + I) T(other[I]);
+
// FIXME: destroy everything in Start
free(Start);
Start = NewStart;
@@ -49,8 +53,7 @@ public:
unsigned Size = size();
for (unsigned I = 0; I != Size; ++I)
- // FIXME: new (NewStart + I) T(Start[I])
- NewStart[I] = Start[I];
+ new (NewStart + I) T(Start[I]);
// FIXME: destruct old values
free(Start);
@@ -60,8 +63,7 @@ public:
End = Start + NewCapacity;
}
- // FIXME: new (Last) T(value);
- *Last = value;
+ new (Last) T(value);
++Last;
}
@@ -100,8 +102,8 @@ struct Point {
// FIXME: remove these when we have implicit instantiation for member
// functions of class templates.
-template struct dynarray<int>;
-template struct dynarray<Point>;
+template class dynarray<int>;
+template class dynarray<Point>;
int main() {
dynarray<int> di;