mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libstdc++: Make allocators throw bad_array_new_length on overflow [LW…
…G 3190] std::allocator and std::pmr::polymorphic_allocator should throw std::bad_array_new_length from their allocate member functions if the number of bytes required cannot be represented in std::size_t. libstdc++-v3/ChangeLog: * config/abi/pre/gnu.ver: Add new symbol. * include/bits/functexcept.h (__throw_bad_array_new_length): Declare new function. * include/ext/malloc_allocator.h (malloc_allocator::allocate): Throw bad_array_new_length for impossible sizes (LWG 3190). * include/ext/new_allocator.h (new_allocator::allocate): Likewise. * include/std/memory_resource (polymorphic_allocator::allocate) (polymorphic_allocator::allocate_object): Use new function, __throw_bad_array_new_length. * src/c++11/functexcept.cc (__throw_bad_array_new_length): Define. * testsuite/20_util/allocator/lwg3190.cc: New test.
- Loading branch information
Showing
7 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2020 Free Software Foundation, Inc. | ||
// | ||
// This file is part of the GNU ISO C++ Library. This library is free | ||
// software; you can redistribute it and/or modify it under the | ||
// terms of the GNU General Public License as published by the | ||
// Free Software Foundation; either version 3, or (at your option) | ||
// any later version. | ||
|
||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License along | ||
// with this library; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
// { dg-do run { target c++11 } } | ||
|
||
#include <memory> | ||
#include <new> | ||
#include <limits> | ||
#include <testsuite_hooks.h> | ||
|
||
// LWG 3190. std::allocator::allocate sometimes returns too little storage | ||
|
||
void | ||
test01() | ||
{ | ||
struct A { char biiiiig[1 << 16]; }; | ||
std::allocator<A> a; | ||
try | ||
{ | ||
std::size_t max = std::numeric_limits<std::size_t>::max() / sizeof(A); | ||
A* p = a.allocate(max + 1); | ||
throw p; | ||
} | ||
#if __cplusplus >= 201103L | ||
catch (const std::bad_array_new_length&) | ||
{ | ||
} | ||
#endif | ||
catch (const std::bad_alloc&) | ||
{ | ||
VERIFY( __cplusplus < 201103L ); | ||
} | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
test01(); | ||
} |