aboutsummaryrefslogtreecommitdiff
path: root/final/ABI-Testsuite/test/s2_7/test01.xpp
diff options
context:
space:
mode:
Diffstat (limited to 'final/ABI-Testsuite/test/s2_7/test01.xpp')
-rwxr-xr-xfinal/ABI-Testsuite/test/s2_7/test01.xpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/final/ABI-Testsuite/test/s2_7/test01.xpp b/final/ABI-Testsuite/test/s2_7/test01.xpp
new file mode 100755
index 00000000..b99af2b8
--- /dev/null
+++ b/final/ABI-Testsuite/test/s2_7/test01.xpp
@@ -0,0 +1,65 @@
+// This file is distributed under the University of Illinois Open Source License.
+// See LICENSE.TXT for details.
+// RUN: cxx_compiler cxx_11 %s -c -o %t.o
+// RUN: linker cxx_11 %t.o -o %t%exeext
+// RUN: runtool %t%exeext | grep "TEST PASSED"
+
+#include <stdio.h>
+#include <new>
+
+// No cookie required for a trivial object
+
+#define BUFF_SIZE 4096
+
+// Globals
+unsigned char alloc_buff[BUFF_SIZE];
+int new_calls = 0;
+int delete_calls = 0;
+
+void *operator new[](size_t size) { new_calls++; return alloc_buff; }
+void operator delete[](void *p) { delete_calls++; }
+
+struct trivial { };
+
+int new_test() {
+ int errors = 0;
+ trivial *ptr = new trivial[2];
+
+ if((void *)ptr != (void *)alloc_buff) {
+ errors++;
+ printf("ERROR: new_test() pointers differ!\n");
+ }
+
+ delete [] ptr;
+
+ return errors;
+}
+
+int placement_new_test() {
+ int errors = 0;
+ trivial *ptr = new (alloc_buff) trivial[5];
+
+ if((void *)ptr != (void *)alloc_buff) {
+ errors++;
+ printf("ERROR: new_test() pointers differ!\n");
+ }
+
+ return errors;
+}
+
+int main(int argc, char *argv[]) {
+ int retval = 0;
+
+ retval += new_test();
+ retval += placement_new_test();
+
+ if(retval) {
+ printf("TEST FAILED\n");
+ retval = 1;
+ } else {
+ printf("TEST PASSED\n");
+ retval = 0;
+ }
+
+ return retval;
+}