47#ifndef _RWSTD_NO_SETRLIMIT
48# include <sys/resource.h>
58# ifndef _RWSTD_NO_PURE_C_HEADERS
68typedef std::jmp_buf sigjmp_buf;
71int __sigsetjmp (sigjmp_buf,
int);
73# define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
75void siglongjmp (sigjmp_buf,
int);
79# define RW_JMP_BUF std::jmp_buf
80# define RW_SETJMP(env) sigsetjmp (env, 0)
81# define RW_LONGJMP(env, val) siglongjmp (env, val)
86# define RW_JMP_BUF jmp_buf
87# define RW_SETJMP(env) sigsetjmp (env, 0)
88# define RW_LONGJMP(env, val) siglongjmp (env, val)
94# define RW_JMP_BUF std::jmp_buf
96# define RW_SETJMP(env) setjmp (env)
98# define RW_SETJMP(env) std::setjmp (env)
100# define RW_LONGJMP(env, val) std::longjmp (env, val)
110 rw_info (0, 0, __LINE__,
"header <exception> synopsis");
120 void (*phandler)() = (std::unexpected_handler)0;
121 phandler = (std::terminate_handler)0;
124 phandler = &std::unexpected;
125 phandler = &std::terminate;
129 std::unexpected_handler (*pset)(std::unexpected_handler)
_PTR_THROWS (());
131 pset = &std::set_unexpected;
132 pset = &std::set_terminate;
147static bool dtor_virtual =
false;
148static bool what_virtual =
false;
156#define MEMFUN(result, T, name, arg_list) do { \
157 result (T::*pf) arg_list _PTR_THROWS (()) = &T::name; \
158 _RWSTD_UNUSED (pf); \
161 rw_info (0, 0, __LINE__,
"std::exception member function signatures");
175 ~test_exception_virtuals ()
_THROWS (()) {
178 const char* what () const
_THROWS (()) {
183 return Base::what ();
192 "std::exception::what() not virtual");
196 "std::exception::~exception() not virtual");
199 rw_info (0, 0, __LINE__,
"std::bad_exception member function signatures");
210 dtor_virtual =
false;
211 what_virtual =
false;
215 ~test_bad_exception_virtuals ()
_THROWS (()) {
218 const char* what () const
_THROWS (()) {
223 return Base::what ();
227 pe =
new test_bad_exception_virtuals;
232 "std::bad_exception::what() not virtual");
236 "std::bad_exception::~bad_exception() not virtual");
242std::unexpected_handler
puh;
243std::terminate_handler
pth;
259 "SIGABRT unexpected");
274test_terminate_handler ()
277 "std::terminate() unexpected");
282 std::signal (
SIGABRT, SIGABRT_handler);
289 "std::terminate() not called or returned");
297test_unexpected_handler ()
300 "std::unexpected() unexpected");
305 std::signal (
SIGABRT, SIGABRT_handler);
317 "std::terminate() not called or returned");
330 const char *what =
e1.what ();
331 rw_assert (what && 1 <= 1 + std::strlen (what), 0, __LINE__,
332 "std::exception::what() != 0");
336 rw_assert (what && 1 <= 1 + std::strlen (what), 0, __LINE__,
337 "std::exception::what() != 0");
342 rw_assert (what && 1 <= 1 + std::strlen (what), 0, __LINE__,
343 "std::bad_exception::what() != 0");
347 rw_assert (what && 1 <= 1 + std::strlen (what), 0, __LINE__,
348 "std::bad_exception::what()");
350#if !defined (_RWSTD_NO_EXCEPTIONS) \
351 && !defined (_RWSTD_NO_EXCEPTION_SPECIFICATION)
354 static void foo () throw (
double) {
359 rw_info (0, 0, __LINE__,
"std::set_unexpected()");
360 rw_info (0, 0, __LINE__,
"std::set_terminate()");
375 rw_assert (0, 0, __LINE__,
"incompatible exception propagated");
396 *
presult_ = std::uncaught_exception ();
401test_uncaught_exception ()
403 rw_info (0, 0, __LINE__,
"std::uncaught_exception()");
408#if !defined (_RWSTD_NO_STD_UNCAUGHT_EXCEPTION) \
409 || !defined (_RWSTD_NO_GLOBAL_UNCAUGHT_EXCEPTION)
415# ifndef _RWSTD_NO_EXCEPTIONS
428 "std::uncaught_exception() == %d, got %d", expect,
uncaught);
430#ifndef _RWSTD_NO_EXCEPTIONS
460 "std::uncaught_exception() == %d, got %d", expect,
uncaught);
466static void (*
const pthrow_proc_save)(int,
char*) = _RW::__rw_throw_proc;
470test_throw_proc (
int id,
char *
s)
473 "throw_proc expected %d, got %d (\"%s\")",
476 _RW::__rw_free_what_buf (
s);
488#ifndef _RWSTD_NO_EXCEPTIONS
490 rw_info (0, 0, __LINE__,
"__rw::__rw_throw()");
496 static const int expect[] = {
517 const char*
const ex_names[] = {
519 "std::bad_exception",
524 "std::invalid_argument",
527 "std::runtime_error",
529 "std::overflow_error",
530 "std::underflow_error",
532 "std::ios_base::failbit_set",
533 "std::ios_base::badbit_set",
534 "std::ios_base::eofbit_set",
535 "std::ios_base::failure"
538 const char empty[] =
"";
542 for (
unsigned i = 0;
i !=
sizeof expect /
sizeof *expect; ++
i) {
544 rw_info (0, 0, __LINE__,
"%s", ex_names [
i]);
549 _RW::__rw_throw_proc = test_throw_proc;
555 const char func[] =
"void test_rwt_hrow (Test&)";
557 _RW::__rw_throw (expect [
i], format,
func, empty, empty, empty);
560 "%d. throw_proc (%d, ...) not called",
i, expect [
i]);
564 _RW::__rw_throw_proc = pthrow_proc_save;
567 _RW::__rw_throw (expect [
i], format,
func, empty, empty, empty);
570 "%d. __rw::__rw_throw(%d, ...) returned",
573 catch (std::domain_error &ex) {
575 "domain_error::what() != 0");
578 catch (std::invalid_argument &ex) {
580 "invalid_argument::what() != 0");
583 catch (std::length_error &ex) {
585 "length_error::what() != 0");
588 catch (std::out_of_range &ex) {
590 "out_of_range::what() != 0");
593 catch (std::range_error &ex) {
595 "range_error::what() != 0");
598 catch (std::overflow_error &ex) {
600 "overflow_error::what() != 0");
603 catch (std::underflow_error &ex) {
605 "underflow_error::what() != 0");
608 catch (std::logic_error &ex) {
610 "logic_error::what() != 0");
613 catch (std::runtime_error &ex) {
615 "runtime_error::what() != 0");
620 "bad_alloc::what() != 0");
625 "bad_exception::what() != 0");
630 "bad_cast::what() != 0");
634#ifdef _RWSTD_ERROR_BAD_TYPEID
636 catch (std::bad_typeid &ex) {
638 "bad_typeid::what() != 0");
639 caught = _RWSTD_ERROR_BAD_TYPEID;
644#ifndef _RWSTD_NO_EXT_FAILURE
646 catch (std::ios_base::failbit_set &ex) {
648 "ios_base::failbit_set::what() != 0");
651 catch (std::ios_base::badbit_set &ex) {
653 "ios_base::badbit_set::what() != 0");
656 catch (std::ios_base::eofbit_set &ex) {
658 "ios_base::eofbit_set::what() != 0");
664 catch (std::ios_base::failure &ex) {
666 "ios_base::failure::what() != 0");
671 "exception::what() != 0");
679 "%d. expected %d, caught %d",
i, expect [
i],
caught);
684 _RW::__rw_throw_proc = pthrow_proc_save;
690 "exercising throwing standard exception objects "
691 "constructed with string arguments up to %zu "
692 "characters long (not including context info)",
698 for (
unsigned j = 0;
j !=
sizeof str - 1; ++
j) {
703 size_t en =
j % ((
sizeof expect /
sizeof *expect) - 5);
708 std::sprintf (
result, strings [en + 5], __FILE__,
str,
709 empty, empty, empty);
713 _RW::__rw_throw (expect [en + 4], __FILE__,
str,
714 empty, empty, empty);
717 "%d. __rw::__rw_throw (%d, ...) returned",
723 "%u. \"%s\" != \"%s\" [%u]",
728 str [
j] =
'0' +
j % 10;
737throwing_unexpected_handler ()
743 struct PrivateStruct { };
751 throw PrivateStruct ();
780#ifndef _RWSTD_NO_NEW_THROWS
782# ifndef _RWSTD_NO_SETRLIMIT
784# if !defined (__HP_aCC)
789 struct rlimit rl = { 0, 0 };
790 if (getrlimit (RLIMIT_DATA, &rl))
795 rw_warn (0 == setrlimit (RLIMIT_DATA, &rl), 0, __LINE__,
796 "setrlimit (RLIMIT_DATA, ...) failed: %m");
804 const std::size_t huge_amount = _RWSTD_SIZE_MAX - 4096;
806 void *
const p = ::operator
new (huge_amount);
808 ::operator
delete (
p);
810# ifndef _RWSTD_NO_SETRLIMIT
811# if !defined (__HP_aCC)
817 rl.rlim_cur = rl.rlim_max;
818 rw_warn (0 == setrlimit (RLIMIT_DATA, &rl), 0, __LINE__,
819 "setrlimit (RLIMIT_DATA, ...) failed: %m");
833 why =
"_RWSTD_NO_NEW_THROWS is #defined";
843#ifndef _RWSTD_NO_DYNAMIC_CAST
855 why =
"_RWSTD_NO_DYNAMIC_CAST is #defined";
864#ifndef _RWSTD_NO_EXCEPTION_SPECIFICATION
878 why =
"_RWSTD_NO_EXCEPTION_SPECIFICATION is #defined";
888#if !defined (_RWSTD_NO_GLOBAL_BAD_TYPEID) \
889 || !defined (_RWSTD_NO_STD_BAD_TYPEID)
891 struct S {
virtual ~S () { } } *
s = 0;
900 why =
"both _RWSTD_NO_GLOBAL_BAD_TYPEID and _RWSTD_NO_STD_BAD_TYPEID "
913 rw_warn (0, 0, __LINE__,
"unable to induce std::%s: %s\n",
name, why);
926static const char*
const
927rt_exception_names[] = {
928 "bad_alloc",
"bad_cast",
"bad_exception",
"bad_typeid"
938#ifndef _RWSTD_NO_EXCEPTIONS
940 rw_info (0, 0, __LINE__,
"runtime support for exceptions");
946 for (
static unsigned i = 0;
E_error != rt_exceptions [
i]; ++
i) {
949 const char*
const ex_name = rt_exception_names [
i];
951 if (0 ==
rw_note (0 <= opt_rt_exception [
i],
953 "std::%s test disabled", ex_name))
956 rw_info (0, 0, __LINE__,
"std::%s", ex_name);
970 if (ex_id == induce_exception (ex_id, ex_name)) {
977 "inducing std::%s caused a call "
978 "to std::terminate()", ex_name);
1002 catch (...) { ex1 = -2; }
1004 rw_assert (-1 == ex0 || 0 == ex0, 0, __LINE__,
1005 "std::%s thrown, std::exception not caught",
1008 rw_assert (-1 == ex1 || rt_exceptions [
i] == ex1, 0, __LINE__,
1009 "std::%s thrown, unknown exception caught",
1018static int opt_synopsis;
1019static int opt_signatures;
1020static int opt_uncaught;
1021static int opt_effects;
1022static int opt_rw_throw;
1023static int opt_runtime;
1028 if (
rw_note (0 <= opt_synopsis, 0, __LINE__,
1029 "test of <exception> synopsis disabled"))
1033 if (
rw_note (0 <= opt_signatures, 0, __LINE__,
1034 "test of function signatures disabled"))
1041 if (
rw_note (0 <= opt_uncaught, 0, __LINE__,
1042 "test of uncaught_exception() disabled"))
1043 test_uncaught_exception ();
1046 if (
rw_note (0 <= opt_rw_throw, 0, __LINE__,
1047 "test of __rw_throw() disabled"))
1052 if (
rw_note (0 <= opt_runtime, 0, __LINE__,
1053 "test of runtime support disabled"))
1058 if (
rw_note (0 <= opt_effects, 0, __LINE__,
1059 "test of effects disabled")) {
1068 "abort() was called unexpectedly");
1071 "terminate() was called unexpectedly");
1074 "unexpected() was called unexpectedly");
1084 return rw_test (argc, argv, __FILE__,
1085 "lib.support.exception",
1090 "|-uncaught_exception~ "
#define MEMFUN(result, T, name, arg_list)
#define RW_LONGJMP(env, val)
std::terminate_handler pth
std::unexpected_handler puh
#define _PTR_THROWS(spec)
void SIGABRT_handler(int)
void test_signatures(Vector *, T *, Allocator)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_UNUSED(arg)
#define _RWSTD_ERROR_OVERFLOW_ERROR
#define _RWSTD_ERROR_IOSTATE_BIT_SET
#define _RWSTD_ERROR_RUNTIME_ERROR
#define _RWSTD_ERROR_STRINGS
#define _RWSTD_ERROR_FAILBIT_SET
#define _RWSTD_ERROR_FIRST
#define _RWSTD_ERROR_RANGE_ERROR
#define _RWSTD_ERROR_LOGIC_ERROR
#define _RWSTD_ERROR_LENGTH_ERROR
#define _RWSTD_ERROR_INVALID_ARGUMENT
#define _RWSTD_ERROR_BADBIT_SET
#define _RWSTD_ERROR_OUT_OF_RANGE
#define _RWSTD_ERROR_UNDERFLOW_ERROR
#define _RWSTD_ERROR_DOMAIN_ERROR
#define _RWSTD_ERROR_EOFBIT_SET
terminate_handler set_terminate(terminate_handler)
unexpected_handler set_unexpected(void(*)())
bool uncaught_exception()
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_error(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
~UncaughtExceptionCheck()