Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
OPERATOR_NEW_ARRAY_PLACEMENT.cpp
Go to the documentation of this file.
1// checking for operator new[] (size_t, void*)
2
3
25#include "config.h"
26
27#include <stddef.h>
28
29#ifdef _RWSTD_NO_EXCEPTION_SPECIFICATION
30# define throw()
31#endif // _RWSTD_NO_EXCEPTION_SPECIFICATION
32
33#ifndef _RWSTD_NO_HONOR_STD
34# ifdef _RWSTD_NO_STD_TERMINATE
35# include "terminate.h"
36# endif // _RWSTD_NO_STD_TERMINATE
37#endif // _RWSTD_NO_HONOR_STD
38
39
40void* operator new[] (size_t, void*) throw ();
41
42void* foo (size_t n, void *p) throw () { return ::operator new[] (n, p); }
43
44void* (*operator_new_array)(size_t, void*);
45
46
47struct S {
48 char c_;
49 char d_;
50
51 S (): c_ ('c'), d_ ('d') { }
52};
53
54
55int main (int argc, char *argv[])
56{
57 (void)&argv;
58
59 int result = 0;
60
61 char buf [sizeof (S) + 32];
62
63 void *p0 = buf;
64
65 void *p1 = ::operator new[] (sizeof (S), p0);
66
67 if (p1 != p0)
68 result = result << 1 + 1;
69
70 if (argc > 1)
71 operator_new_array = &operator new[];
72 else
74
75 p1 = operator_new_array (sizeof (S), p0);
76
77 if (p1 != p0)
78 result = (result << 1) + 1;
79
80 S *s = new (p0) S [1];
81
82 if (p1 != p0)
83 result = (result << 1) + 1;
84
85 if (s->c_ != 'c' || s->d_ != 'd')
86 result = (result << 1) + 1;
87
88 // prevent compilers from optimizing the code above away
89 // without actually ever using the result (unless the
90 // test is invoked with command line arguments)
91 if (argc > 1)
92 return result;
93
94 return 0;
95}
#define buf
Definition 17.names.cpp:452
#define s
#define n
Definition 17.names.cpp:130
#define p1
Definition 17.names.cpp:239
#define p
Definition 17.names.cpp:132
#define d_
Definition 17.names.cpp:175
#define S
Definition 17.names.cpp:162
#define c_
Definition 17.names.cpp:174
volatile int result
#define main
void *(* operator_new_array)(size_t, void *)
#define foo(buf, s,...)