]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/cxa_vec.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / cxa_vec.cc
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-2020 Free Software Foundation, Inc.
6 // Contributed by Nathan Sidwell 7 Apr 2000 <nathan@nathan@codesourcery.com>
7
8 #include <cxxabi.h>
9 #include <stdio.h>
10 #include <new>
11 #include <stdlib.h>
12 #include <setjmp.h>
13
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
20
21 // our pseudo ctors and dtors
22 static abi::__cxa_cdtor_return_type ctor (void *x)
23 {
24 abort ();
25 }
26
27 static abi::__cxa_cdtor_return_type dtor (void *x)
28 {
29 abort ();
30 }
31
32 // allocate an array whose size causes an overflow during multiplication
33 void test1 ()
34 {
35 static const std::size_t large_size =
36 std::size_t(1) << (sizeof(std::size_t) * 8 - 2);
37 try
38 {
39 abi::__cxa_vec_new (large_size, 8, 0, ctor, dtor);
40 abort ();
41 }
42 catch (std::bad_alloc &)
43 {
44 }
45 }
46
47 // allocate an array whose size causes an overflow during addition
48 void test2 ()
49 {
50 try
51 {
52 abi::__cxa_vec_new (std::size_t(-1) / 4, 4, padding, ctor, dtor);
53 abort ();
54 }
55 catch (std::bad_alloc &)
56 {
57 }
58 }
59
60 int main ()
61 {
62 test1 ();
63 test2 ();
64 }