2015-05-19 Christophe Lyon <christophe.lyon@linaro.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / cxa_vec.cc
blob75650bf1cc9934df87f0fb0ebb0f586c3ca57717
1 // { dg-do run }
2 // Avoid use of non-overridable new/delete operators in shared
3 // { dg-options "-static" { target *-*-mingw* } }
4 // Test __cxa_vec routines
5 // Copyright (C) 2000-2015 Free Software Foundation, Inc.
6 // Contributed by Nathan Sidwell 7 Apr 2000 <nathan@nathan@codesourcery.com>
8 #include <cxxabi.h>
9 #include <stdio.h>
10 #include <new>
11 #include <stdlib.h>
12 #include <setjmp.h>
14 // Allocate enough padding to hold an array cookie.
15 #ifdef __ARM_EABI__
16 static const size_t padding = 8;
17 #else
18 static const size_t padding = (sizeof (std::size_t));
19 #endif
21 // our pseudo ctors and dtors
22 static abi::__cxa_cdtor_return_type ctor (void *x)
24 abort ();
27 static abi::__cxa_cdtor_return_type dtor (void *x)
29 abort ();
32 // allocate an array whose size causes an overflow during multiplication
33 void test1 ()
35 static const std::size_t large_size =
36 std::size_t(1) << (sizeof(std::size_t) * 8 - 2);
37 try
39 abi::__cxa_vec_new (large_size, 8, 0, ctor, dtor);
40 abort ();
42 catch (std::bad_alloc &)
47 // allocate an array whose size causes an overflow during addition
48 void test2 ()
50 try
52 abi::__cxa_vec_new (std::size_t(-1) / 4, 4, padding, ctor, dtor);
53 abort ();
55 catch (std::bad_alloc &)
60 int main ()
62 test1 ();
63 test2 ();