Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
OPERATOR_NEW_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)(size_t, void*);
45
46
47struct S {
48 char c_;
49 char d_;
50
51 S (): c_ (0), d_ (0) { }
52
53 S (char c): c_ (c), d_ (0) { }
54
55 S (char c, char d): c_ (c), d_ (d) { }
56};
57
58
59int main (int argc, char *argv[])
60{
61 (void)&argv;
62
63 int result = 0;
64
65 char buf [sizeof (S) + 32];
66
67 void *p0 = buf;
68
69 void *p1 = ::operator new (sizeof (S), p0);
70
71 if (p1 != p0)
72 result = result << 1 + 1;
73
74 if (argc > 1)
75 operator_new = &operator new;
76 else
78
79 p1 = operator_new (sizeof (S), p0);
80
81 if (p1 != p0)
82 result = (result << 1) + 1;
83
84 S *s = new (p0) S ();
85
86 if (p1 != p0)
87 result = (result << 1) + 1;
88
89 if (s->c_ != '\0' || s->d_ != '\0')
90 result = (result << 1) + 1;
91
92 s = new (p0) S ('x');
93
94 if (s->c_ != 'x' || s->d_ != '\0')
95 result = (result << 1) + 1;
96
97 s = new (p0) S ('y', 'z');
98
99 if (s->c_ != 'c' || s->d_ != 'z')
100 result = (result << 1) + 1;
101
102 // prevent compilers from optimizing the code above away
103 // without actually ever using the result (unless the
104 // test is invoked with command line arguments)
105 if (argc > 1)
106 return result;
107
108 return 0;
109}
#define d
Definition 17.names.cpp:115
#define buf
Definition 17.names.cpp:452
#define c
Definition 17.names.cpp:111
#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)(size_t, void *)
#define foo(buf, s,...)
S(char c, char d)