Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
etc
config
src
NEW_THROWS.cpp
Go to the documentation of this file.
1
// checking if operator new() throws
2
3
25
#include <
stddef.h
>
26
27
#include "config.h"
28
#include "
nodbg.h
"
29
30
#ifndef _RWSTD_NO_SETRLIMIT
31
// test for setrlimit() presence before compiling current file
32
#endif
// _RWSTD_NO_SETRLIMIT
33
34
// proclimits.h must be included only after #if[n]def _RWSTD_NO_SETRLIMIT
35
#include "
proclimits.h
"
36
37
#if 2 == __GNUG__
38
# ifndef _RWSTD_NO_HONOR_STD
39
# ifdef _RWSTD_NO_STD_TERMINATE
40
# include "
terminate.h
"
41
# endif
// _RWSTD_NO_STD_TERMINATE
42
# endif
// _RWSTD_NO_HONOR_STD
43
#endif
// gcc 2.x
44
45
#ifndef _RWSTD_NO_NEW_OFLOW_SAFE
46
// test if operator new() checks the argument for overflow
47
#endif
// _RWSTD_NO_NEW_OFLOW_SAFE
48
49
50
// 18.4.1.1
51
// -3- Required behavior: Return a non-null pointer ... or else throw
52
// a bad_alloc exception.
53
54
int
main
()
55
{
56
nodbg
();
57
58
// decrease resource limit to a minimum to induce a failure
59
// without unreasonably stressing the system
60
limit_memory
(0);
61
62
void
*
p
= (
void
*)1;
63
64
try
{
65
const
size_t
size
= (size_t)1 << (
sizeof
(
size_t
) * 8 - 1);
66
67
for
(
int
i
= 0;
i
!= 256; ++
i
) {
68
// try to allocate a huge amount of memory
69
p
= ::operator
new
(
size
);
70
// do not delete
71
}
72
}
73
catch
(...) {
74
return
0;
75
}
76
77
return
1;
78
}
i
#define i
Definition
17.names.cpp:126
p
#define p
Definition
17.names.cpp:132
main
int main()
Definition
NEW_THROWS.cpp:54
size
int size
Definition
TEMPLATE_ON_RETURN_TYPE.cpp:45
nodbg.h
nodbg
void nodbg()
Definition
nodbg.h:52
proclimits.h
limit_memory
void limit_memory(unsigned long limit)
Definition
proclimits.h:30
stddef.h
terminate.h
Generated by
1.9.8