//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// test placement new array

#include <new>
#include <cassert>

int A_constructed = 0;

struct A
{
    A() {++A_constructed;}
    ~A() {--A_constructed;}
};

int main()
{
    const std::size_t Size = 3;
    // placement new might require additional space.
    const std::size_t ExtraSize = 64;
    char buf[Size*sizeof(A) + ExtraSize];

    A* ap = new(buf) A[Size];
    assert((char*)ap >= buf);
    assert((char*)ap < (buf + ExtraSize));
    assert(A_constructed == Size);
}

//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// test placement new array

#include <new>
#include <cassert>

int A_constructed = 0;

struct A
{
    A() {++A_constructed;}
    ~A() {--A_constructed;}
};

int main()
{
    char buf[3*sizeof(A)];

    A* ap = new(buf) A[3];
    assert((char*)ap == buf);
    assert(A_constructed == 3);
}

--- 
+++ 
@@ -22,9 +22,13 @@
 
 int main()
 {
-    char buf[3*sizeof(A)];
+    const std::size_t Size = 3;
+    // placement new might require additional space.
+    const std::size_t ExtraSize = 64;
+    char buf[Size*sizeof(A) + ExtraSize];
 
-    A* ap = new(buf) A[3];
-    assert((char*)ap == buf);
-    assert(A_constructed == 3);
+    A* ap = new(buf) A[Size];
+    assert((char*)ap >= buf);
+    assert((char*)ap < (buf + ExtraSize));
+    assert(A_constructed == Size);
 }
Allow placement new array test to consume extra bytes as specified by the standard.

git-svn-id: 756ef344af921d95d562d9e9f9389127a89a6314@273342 91177308-0d34-0410-b5e6-96231b3b80d8
