]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator/lwg3190.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator / lwg3190.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++11 } }
19 // { dg-require-effective-target hosted }
20
21 #include <memory>
22 #include <new>
23 #include <limits>
24 #include <testsuite_hooks.h>
25
26 // LWG 3190. std::allocator::allocate sometimes returns too little storage
27
28 void
29 test01()
30 {
31 struct A { char biiiiig[1 << 16]; };
32 std::allocator<A> a;
33 try
34 {
35 std::size_t max = std::numeric_limits<std::size_t>::max() / sizeof(A);
36 A* p = a.allocate(max + 1);
37 throw p;
38 }
39 #if __cplusplus >= 201103L
40 catch (const std::bad_array_new_length&)
41 {
42 }
43 #endif
44 catch (const std::bad_alloc&)
45 {
46 VERIFY( __cplusplus < 201103L );
47 }
48 }
49
50 int
51 main()
52 {
53 test01();
54 }