2006-09-19 02:33:21 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
2023-01-16 11:50:43 +01:00
|
|
|
// Copyright (C) 2005-2023 Free Software Foundation, Inc.
|
2006-09-19 02:33:21 +00:00
|
|
|
//
|
|
|
|
// 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
|
2009-04-09 17:00:19 +02:00
|
|
|
// Foundation; either version 3, or (at your option) any later
|
2006-09-19 02:33:21 +00:00
|
|
|
// 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.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2006-09-19 02:33:21 +00:00
|
|
|
|
|
|
|
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
|
|
|
|
|
|
|
|
// Permission to use, copy, modify, sell, and distribute this software
|
|
|
|
// is hereby granted without fee, provided that the above copyright
|
|
|
|
// notice appears in all copies, and that both that copyright notice
|
|
|
|
// and this permission notice appear in supporting documentation. None
|
|
|
|
// of the above authors, nor IBM Haifa Research Laboratories, make any
|
|
|
|
// representation about the suitability of this software for any
|
|
|
|
// purpose. It is provided "as is" without express or implied
|
|
|
|
// warranty.
|
|
|
|
|
2007-08-22 01:26:43 +00:00
|
|
|
/** @file ext/throw_allocator.h
|
2006-11-29 20:59:22 +00:00
|
|
|
* This file is a GNU extension to the Standard C++ Library.
|
|
|
|
*
|
2009-12-16 05:16:46 +00:00
|
|
|
* Contains two exception-generating types (throw_value, throw_allocator)
|
|
|
|
* intended to be used as value and allocator types while testing
|
|
|
|
* exception safety in templatized containers and algorithms. The
|
|
|
|
* allocator has additional log and debug features. The exception
|
|
|
|
* generated is of type forced_exception_error.
|
2006-11-29 20:59:22 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-19 02:33:21 +00:00
|
|
|
#ifndef _THROW_ALLOCATOR_H
|
|
|
|
#define _THROW_ALLOCATOR_H 1
|
|
|
|
|
2022-09-19 21:54:49 +02:00
|
|
|
#include <bits/requires_hosted.h> // GNU extensions are currently omitted
|
|
|
|
|
2006-09-19 02:33:21 +00:00
|
|
|
#include <cmath>
|
2007-05-27 14:50:21 +00:00
|
|
|
#include <ctime>
|
2006-09-19 02:33:21 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <ostream>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <utility>
|
2007-06-26 11:01:15 +00:00
|
|
|
#include <bits/functexcept.h>
|
2008-06-21 16:55:17 +00:00
|
|
|
#include <bits/move.h>
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2009-06-05 08:45:26 +00:00
|
|
|
# include <functional>
|
|
|
|
# include <random>
|
|
|
|
#else
|
|
|
|
# include <tr1/functional>
|
|
|
|
# include <tr1/random>
|
|
|
|
#endif
|
Remove redundant std::allocator members for C++20
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.
Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.
* include/bits/alloc_traits.h
(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
(allocator_traits<allocator<T>>::construct): Perform placement new
directly for C++20, instead of calling allocator<T>::construct.
(allocator_traits<allocator<T>>::destroy): Call destructor directly
for C++20, instead of calling allocator<T>::destroy.
(allocator_traits<allocator<T>>::max_size): Return value directly
for C++20, instead of calling std::allocator<T>::max_size().
(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
define for C++17 and up.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
for C++17 and up, instead of tag dispatching.
* include/bits/allocator.h (allocator<void>): Remove for C++20.
(allocator::pointer, allocator::const_pointer, allocator::reference)
(allocator::const_reference, allocator::rebind): Remove for C++20.
* include/bits/basic_string.h (basic_string): Use __alloc_traits to
rebind allocator.
* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
(malloc_allocator::pointer, malloc_allocator::const_pointer)
(malloc_allocator::reference, malloc_allocator::const_reference)
(malloc_allocator::rebind, malloc_allocator::max_size)
(malloc_allocator::construct, malloc_allocator::destroy): Do not
define for C++20.
(malloc_allocator::_M_max_size): Define new function.
* include/ext/new_allocator.h (new_allocator::~new_allocator)
(new_allocator::pointer, new_allocator::const_pointer)
(new_allocator::reference, new_allocator::const_reference)
(new_allocator::rebind, new_allocator::max_size)
(new_allocator::construct, new_allocator::destroy): Do not
define for C++20.
(new_allocator::_M_max_size): Define new function.
* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
__alloc_traits to rebind allocator.
* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
to construct character.
* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
allocator.
* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
Use __alloc_traits.
* include/ext/throw_allocator.h (throw_allocator): Do not use optional
members of std::allocator, use __alloc_traits members instead.
* include/ext/vstring.h (__versa_string): Use __alloc_traits.
* include/ext/vstring_util.h (__vstring_utility): Likewise.
* include/std/memory: Include <bits/alloc_traits.h>.
* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
* testsuite/20_util/allocator/rebind_c++20.cc: New test.
* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
for pointer, const_pointer, reference, const_reference or rebind in
C++20.
* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
* testsuite/23_containers/deque/capacity/29134.cc: Use
__gnu_test::max_size.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/list/capacity/29134.cc: Likewise.
* testsuite/23_containers/map/capacity/29134.cc: Likewise.
* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
* testsuite/23_containers/set/capacity/29134.cc: Likewise.
* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
test for C++20.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
* testsuite/util/replacement_memory_operators.h: Do not assume
Alloc::pointer exists.
* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
helper to call max_size for any allocator.
From-SVN: r277300
2019-10-22 22:48:39 +01:00
|
|
|
#include <ext/alloc_traits.h>
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2020-12-16 13:50:34 +00:00
|
|
|
#if !__has_builtin(__builtin_sprintf)
|
|
|
|
# include <cstdio>
|
|
|
|
#endif
|
|
|
|
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 22:39:36 +00:00
|
|
|
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
|
|
|
|
{
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
/**
|
2021-07-01 00:30:54 +01:00
|
|
|
* @brief Thrown by utilities for testing exception safety.
|
2009-02-21 00:45:21 +00:00
|
|
|
* @ingroup exceptions
|
|
|
|
*/
|
2009-12-16 05:16:46 +00:00
|
|
|
struct forced_error : public std::exception
|
2006-09-19 02:33:21 +00:00
|
|
|
{ };
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
// Substitute for forced_error object when -fno-exceptions.
|
2007-06-26 11:01:15 +00:00
|
|
|
inline void
|
2009-12-16 05:16:46 +00:00
|
|
|
__throw_forced_error()
|
2012-11-07 13:20:33 +00:00
|
|
|
{ _GLIBCXX_THROW_OR_ABORT(forced_error()); }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Base class for checking address and label information
|
|
|
|
* about allocations. Create a std::map between the allocated
|
|
|
|
* address (void*) and a datum for annotations, which are a pair of
|
|
|
|
* numbers corresponding to label and allocated size.
|
|
|
|
*/
|
2009-06-05 08:45:26 +00:00
|
|
|
struct annotate_base
|
2006-09-19 02:33:21 +00:00
|
|
|
{
|
2018-11-19 21:02:17 +00:00
|
|
|
private:
|
|
|
|
typedef std::pair<size_t, size_t> data_type;
|
|
|
|
typedef std::map<void*, data_type> map_alloc_type;
|
|
|
|
typedef map_alloc_type::value_type entry_type;
|
|
|
|
typedef map_alloc_type::const_iterator const_iterator;
|
|
|
|
typedef map_alloc_type::const_reference const_reference;
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
typedef std::map<void*, size_t> map_construct_type;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2009-06-05 08:45:26 +00:00
|
|
|
annotate_base()
|
|
|
|
{
|
|
|
|
label();
|
2013-04-22 20:22:07 +00:00
|
|
|
map_alloc();
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
static void
|
|
|
|
set_label(size_t l)
|
|
|
|
{ label() = l; }
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
get_label()
|
|
|
|
{ return label(); }
|
|
|
|
|
2006-09-19 02:33:21 +00:00
|
|
|
void
|
2009-06-05 08:45:26 +00:00
|
|
|
insert(void* p, size_t size)
|
|
|
|
{
|
2018-11-19 21:02:17 +00:00
|
|
|
entry_type entry = make_entry(p, size);
|
2010-06-03 19:15:56 +00:00
|
|
|
if (!p)
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
std::string error("annotate_base::insert null insert!\n");
|
2018-11-19 21:02:17 +00:00
|
|
|
log_to_string(error, entry);
|
2009-06-05 08:45:26 +00:00
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2018-11-19 21:02:17 +00:00
|
|
|
std::pair<map_alloc_type::iterator, bool> inserted
|
|
|
|
= map_alloc().insert(entry);
|
|
|
|
if (!inserted.second)
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
std::string error("annotate_base::insert double insert!\n");
|
2018-11-19 21:02:17 +00:00
|
|
|
log_to_string(error, entry);
|
|
|
|
log_to_string(error, *inserted.first);
|
2009-06-05 08:45:26 +00:00
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
void
|
|
|
|
erase(void* p, size_t size)
|
2018-11-19 21:02:17 +00:00
|
|
|
{ map_alloc().erase(check_allocated(p, size)); }
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2013-04-22 20:22:07 +00:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
void
|
|
|
|
insert_construct(void* p)
|
|
|
|
{
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
std::string error("annotate_base::insert_construct null!\n");
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
|
|
|
|
2018-11-19 21:02:17 +00:00
|
|
|
auto inserted = map_construct().insert(std::make_pair(p, get_label()));
|
|
|
|
if (!inserted.second)
|
2013-04-22 20:22:07 +00:00
|
|
|
{
|
|
|
|
std::string error("annotate_base::insert_construct double insert!\n");
|
|
|
|
log_to_string(error, std::make_pair(p, get_label()));
|
2018-11-19 21:02:17 +00:00
|
|
|
log_to_string(error, *inserted.first);
|
2013-04-22 20:22:07 +00:00
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
erase_construct(void* p)
|
2018-11-19 21:02:17 +00:00
|
|
|
{ map_construct().erase(check_constructed(p)); }
|
2013-04-22 20:22:07 +00:00
|
|
|
#endif
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
// See if a particular address and allocation size has been saved.
|
2018-11-19 21:02:17 +00:00
|
|
|
inline map_alloc_type::iterator
|
2009-06-05 08:45:26 +00:00
|
|
|
check_allocated(void* p, size_t size)
|
|
|
|
{
|
2018-11-19 21:02:17 +00:00
|
|
|
map_alloc_type::iterator found = map_alloc().find(p);
|
2013-04-22 20:22:07 +00:00
|
|
|
if (found == map_alloc().end())
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
|
|
|
std::string error("annotate_base::check_allocated by value "
|
|
|
|
"null erase!\n");
|
|
|
|
log_to_string(error, make_entry(p, size));
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
if (found->second.second != size)
|
|
|
|
{
|
|
|
|
std::string error("annotate_base::check_allocated by value "
|
|
|
|
"wrong-size erase!\n");
|
|
|
|
log_to_string(error, make_entry(p, size));
|
|
|
|
log_to_string(error, *found);
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
2018-11-19 21:02:17 +00:00
|
|
|
|
|
|
|
return found;
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
// See if a given label has been allocated.
|
|
|
|
inline void
|
2013-04-22 20:22:07 +00:00
|
|
|
check(size_t label)
|
|
|
|
{
|
|
|
|
std::string found;
|
|
|
|
{
|
|
|
|
const_iterator beg = map_alloc().begin();
|
|
|
|
const_iterator end = map_alloc().end();
|
|
|
|
while (beg != end)
|
|
|
|
{
|
|
|
|
if (beg->second.first == label)
|
|
|
|
log_to_string(found, *beg);
|
|
|
|
++beg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
{
|
|
|
|
auto beg = map_construct().begin();
|
|
|
|
auto end = map_construct().end();
|
|
|
|
while (beg != end)
|
|
|
|
{
|
|
|
|
if (beg->second == label)
|
|
|
|
log_to_string(found, *beg);
|
|
|
|
++beg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!found.empty())
|
|
|
|
{
|
|
|
|
std::string error("annotate_base::check by label\n");
|
|
|
|
error += found;
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if there is anything left allocated or constructed.
|
|
|
|
inline static void
|
|
|
|
check()
|
|
|
|
{
|
|
|
|
std::string found;
|
|
|
|
{
|
|
|
|
const_iterator beg = map_alloc().begin();
|
|
|
|
const_iterator end = map_alloc().end();
|
|
|
|
while (beg != end)
|
|
|
|
{
|
|
|
|
log_to_string(found, *beg);
|
|
|
|
++beg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
{
|
|
|
|
auto beg = map_construct().begin();
|
|
|
|
auto end = map_construct().end();
|
|
|
|
while (beg != end)
|
|
|
|
{
|
|
|
|
log_to_string(found, *beg);
|
|
|
|
++beg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!found.empty())
|
|
|
|
{
|
|
|
|
std::string error("annotate_base::check \n");
|
|
|
|
error += found;
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
2018-11-19 21:02:17 +00:00
|
|
|
inline map_construct_type::iterator
|
2013-04-22 20:22:07 +00:00
|
|
|
check_constructed(void* p)
|
|
|
|
{
|
|
|
|
auto found = map_construct().find(p);
|
|
|
|
if (found == map_construct().end())
|
|
|
|
{
|
|
|
|
std::string error("annotate_base::check_constructed not "
|
|
|
|
"constructed!\n");
|
|
|
|
log_to_string(error, std::make_pair(p, get_label()));
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
2018-11-19 21:02:17 +00:00
|
|
|
|
|
|
|
return found;
|
2013-04-22 20:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
check_constructed(size_t label)
|
2006-09-19 02:33:21 +00:00
|
|
|
{
|
2013-04-22 20:22:07 +00:00
|
|
|
auto beg = map_construct().begin();
|
|
|
|
auto end = map_construct().end();
|
2009-06-05 08:45:26 +00:00
|
|
|
std::string found;
|
|
|
|
while (beg != end)
|
|
|
|
{
|
2013-04-22 20:22:07 +00:00
|
|
|
if (beg->second == label)
|
2009-06-05 08:45:26 +00:00
|
|
|
log_to_string(found, *beg);
|
|
|
|
++beg;
|
|
|
|
}
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
if (!found.empty())
|
|
|
|
{
|
2013-04-22 20:22:07 +00:00
|
|
|
std::string error("annotate_base::check_constructed by label\n");
|
2009-06-05 08:45:26 +00:00
|
|
|
error += found;
|
|
|
|
std::__throw_logic_error(error.c_str());
|
|
|
|
}
|
|
|
|
}
|
2013-04-22 20:22:07 +00:00
|
|
|
#endif
|
2009-06-05 08:45:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend std::ostream&
|
|
|
|
operator<<(std::ostream&, const annotate_base&);
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
entry_type
|
|
|
|
make_entry(void* p, size_t size)
|
|
|
|
{ return std::make_pair(p, data_type(get_label(), size)); }
|
|
|
|
|
2013-04-22 20:22:07 +00:00
|
|
|
static void
|
|
|
|
log_to_string(std::string& s, const_reference ref)
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
2020-12-16 13:50:34 +00:00
|
|
|
#if ! __has_builtin(__builtin_sprintf)
|
|
|
|
__typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
char buf[40];
|
|
|
|
const char tab('\t');
|
|
|
|
s += "label: ";
|
|
|
|
unsigned long l = static_cast<unsigned long>(ref.second.first);
|
|
|
|
__builtin_sprintf(buf, "%lu", l);
|
|
|
|
s += buf;
|
|
|
|
s += tab;
|
|
|
|
s += "size: ";
|
|
|
|
l = static_cast<unsigned long>(ref.second.second);
|
|
|
|
__builtin_sprintf(buf, "%lu", l);
|
|
|
|
s += buf;
|
|
|
|
s += tab;
|
|
|
|
s += "address: ";
|
|
|
|
__builtin_sprintf(buf, "%p", ref.first);
|
|
|
|
s += buf;
|
|
|
|
s += '\n';
|
|
|
|
}
|
|
|
|
|
2013-04-22 20:22:07 +00:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
static void
|
|
|
|
log_to_string(std::string& s, const std::pair<const void*, size_t>& ref)
|
|
|
|
{
|
2020-12-16 13:50:34 +00:00
|
|
|
#if ! __has_builtin(__builtin_sprintf)
|
|
|
|
auto __builtin_sprintf = &std::sprintf;
|
|
|
|
#endif
|
|
|
|
|
2013-04-22 20:22:07 +00:00
|
|
|
char buf[40];
|
|
|
|
const char tab('\t');
|
|
|
|
s += "label: ";
|
|
|
|
unsigned long l = static_cast<unsigned long>(ref.second);
|
|
|
|
__builtin_sprintf(buf, "%lu", l);
|
|
|
|
s += buf;
|
|
|
|
s += tab;
|
|
|
|
s += "address: ";
|
|
|
|
__builtin_sprintf(buf, "%p", ref.first);
|
|
|
|
s += buf;
|
|
|
|
s += '\n';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
static size_t&
|
|
|
|
label()
|
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
static size_t _S_label(std::numeric_limits<size_t>::max());
|
|
|
|
return _S_label;
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 20:22:07 +00:00
|
|
|
static map_alloc_type&
|
|
|
|
map_alloc()
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
2013-04-22 20:22:07 +00:00
|
|
|
static map_alloc_type _S_map;
|
2009-12-16 05:16:46 +00:00
|
|
|
return _S_map;
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
2013-04-22 20:22:07 +00:00
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
static map_construct_type&
|
|
|
|
map_construct()
|
|
|
|
{
|
|
|
|
static map_construct_type _S_map;
|
|
|
|
return _S_map;
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-05 08:45:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream&
|
|
|
|
operator<<(std::ostream& os, const annotate_base& __b)
|
|
|
|
{
|
|
|
|
std::string error;
|
|
|
|
typedef annotate_base base_type;
|
2013-04-22 20:22:07 +00:00
|
|
|
{
|
|
|
|
base_type::const_iterator beg = __b.map_alloc().begin();
|
|
|
|
base_type::const_iterator end = __b.map_alloc().end();
|
|
|
|
for (; beg != end; ++beg)
|
|
|
|
__b.log_to_string(error, *beg);
|
|
|
|
}
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
{
|
|
|
|
auto beg = __b.map_construct().begin();
|
|
|
|
auto end = __b.map_construct().end();
|
|
|
|
for (; beg != end; ++beg)
|
|
|
|
__b.log_to_string(error, *beg);
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-05 08:45:26 +00:00
|
|
|
return os << error;
|
|
|
|
}
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Base struct for condition policy.
|
|
|
|
*
|
|
|
|
* Requires a public member function with the signature
|
|
|
|
* void throw_conditionally()
|
|
|
|
*/
|
|
|
|
struct condition_base
|
|
|
|
{
|
2018-05-18 16:02:14 -04:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
condition_base() = default;
|
|
|
|
condition_base(const condition_base&) = default;
|
|
|
|
condition_base& operator=(const condition_base&) = default;
|
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
virtual ~condition_base() { };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Base class for incremental control and throw.
|
|
|
|
*/
|
|
|
|
struct limit_condition : public condition_base
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
// Scope-level adjustor objects: set limit for throw at the
|
|
|
|
// beginning of a scope block, and restores to previous limit when
|
|
|
|
// object is destroyed on exiting the block.
|
2009-06-05 08:45:26 +00:00
|
|
|
struct adjustor_base
|
|
|
|
{
|
2006-09-19 02:33:21 +00:00
|
|
|
private:
|
2009-12-16 05:16:46 +00:00
|
|
|
const size_t _M_orig;
|
2009-06-05 08:45:26 +00:00
|
|
|
|
|
|
|
public:
|
2009-12-16 05:16:46 +00:00
|
|
|
adjustor_base() : _M_orig(limit()) { }
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~adjustor_base() { set_limit(_M_orig); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Never enter the condition.
|
|
|
|
struct never_adjustor : public adjustor_base
|
|
|
|
{
|
|
|
|
never_adjustor() { set_limit(std::numeric_limits<size_t>::max()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Always enter the condition.
|
|
|
|
struct always_adjustor : public adjustor_base
|
|
|
|
{
|
|
|
|
always_adjustor() { set_limit(count()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Enter the nth condition.
|
|
|
|
struct limit_adjustor : public adjustor_base
|
|
|
|
{
|
|
|
|
limit_adjustor(const size_t __l) { set_limit(__l); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Increment _S_count every time called.
|
|
|
|
// If _S_count matches the limit count, throw.
|
|
|
|
static void
|
|
|
|
throw_conditionally()
|
|
|
|
{
|
|
|
|
if (count() == limit())
|
|
|
|
__throw_forced_error();
|
|
|
|
++count();
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t&
|
|
|
|
count()
|
|
|
|
{
|
|
|
|
static size_t _S_count(0);
|
|
|
|
return _S_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t&
|
|
|
|
limit()
|
|
|
|
{
|
|
|
|
static size_t _S_limit(std::numeric_limits<size_t>::max());
|
|
|
|
return _S_limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zero the throw counter, set limit to argument.
|
|
|
|
static void
|
|
|
|
set_limit(const size_t __l)
|
|
|
|
{
|
|
|
|
limit() = __l;
|
|
|
|
count() = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Base class for random probability control and throw.
|
|
|
|
*/
|
|
|
|
struct random_condition : public condition_base
|
|
|
|
{
|
|
|
|
// Scope-level adjustor objects: set probability for throw at the
|
|
|
|
// beginning of a scope block, and restores to previous
|
|
|
|
// probability when object is destroyed on exiting the block.
|
|
|
|
struct adjustor_base
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const double _M_orig;
|
|
|
|
|
|
|
|
public:
|
|
|
|
adjustor_base() : _M_orig(probability()) { }
|
2009-06-05 08:45:26 +00:00
|
|
|
|
|
|
|
virtual ~adjustor_base()
|
2009-12-16 05:16:46 +00:00
|
|
|
{ set_probability(_M_orig); }
|
2006-09-19 02:33:21 +00:00
|
|
|
};
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
/// Group condition.
|
2009-06-05 08:45:26 +00:00
|
|
|
struct group_adjustor : public adjustor_base
|
2006-09-19 02:33:21 +00:00
|
|
|
{
|
2009-06-05 08:45:26 +00:00
|
|
|
group_adjustor(size_t size)
|
2009-12-16 05:16:46 +00:00
|
|
|
{ set_probability(1 - std::pow(double(1 - probability()),
|
2009-06-05 08:45:26 +00:00
|
|
|
double(0.5 / (size + 1))));
|
|
|
|
}
|
|
|
|
};
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
/// Never enter the condition.
|
2009-06-05 08:45:26 +00:00
|
|
|
struct never_adjustor : public adjustor_base
|
|
|
|
{
|
|
|
|
never_adjustor() { set_probability(0); }
|
|
|
|
};
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
/// Always enter the condition.
|
2009-06-05 08:45:26 +00:00
|
|
|
struct always_adjustor : public adjustor_base
|
|
|
|
{
|
|
|
|
always_adjustor() { set_probability(1); }
|
2006-09-19 02:33:21 +00:00
|
|
|
};
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
random_condition()
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
|
|
|
probability();
|
|
|
|
engine();
|
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
|
|
|
static void
|
2009-06-05 08:45:26 +00:00
|
|
|
set_probability(double __p)
|
|
|
|
{ probability() = __p; }
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
static void
|
2009-06-05 08:45:26 +00:00
|
|
|
throw_conditionally()
|
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
if (generate() < probability())
|
|
|
|
__throw_forced_error();
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
void
|
|
|
|
seed(unsigned long __s)
|
|
|
|
{ engine().seed(__s); }
|
2006-09-19 02:33:21 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2009-06-05 08:45:26 +00:00
|
|
|
typedef std::uniform_real_distribution<double> distribution_type;
|
|
|
|
typedef std::mt19937 engine_type;
|
|
|
|
#else
|
|
|
|
typedef std::tr1::uniform_real<double> distribution_type;
|
|
|
|
typedef std::tr1::mt19937 engine_type;
|
|
|
|
#endif
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
static double
|
2009-06-05 08:45:26 +00:00
|
|
|
generate()
|
|
|
|
{
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2009-06-05 08:45:26 +00:00
|
|
|
const distribution_type distribution(0, 1);
|
|
|
|
static auto generator = std::bind(distribution, engine());
|
|
|
|
#else
|
|
|
|
// Use variate_generator to get normalized results.
|
|
|
|
typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t;
|
|
|
|
distribution_type distribution(0, 1);
|
|
|
|
static gen_t generator(engine(), distribution);
|
|
|
|
#endif
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2020-12-16 13:50:34 +00:00
|
|
|
#if ! __has_builtin(__builtin_sprintf)
|
|
|
|
__typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
double random = generator();
|
|
|
|
if (random < distribution.min() || random > distribution.max())
|
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
std::string __s("random_condition::generate");
|
2009-06-05 08:45:26 +00:00
|
|
|
__s += "\n";
|
|
|
|
__s += "random number generated is: ";
|
|
|
|
char buf[40];
|
|
|
|
__builtin_sprintf(buf, "%f", random);
|
|
|
|
__s += buf;
|
|
|
|
std::__throw_out_of_range(__s.c_str());
|
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
return random;
|
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
static double&
|
|
|
|
probability()
|
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
static double _S_p;
|
|
|
|
return _S_p;
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
static engine_type&
|
|
|
|
engine()
|
|
|
|
{
|
2009-12-16 05:16:46 +00:00
|
|
|
static engine_type _S_e;
|
|
|
|
return _S_e;
|
2009-06-05 08:45:26 +00:00
|
|
|
}
|
2006-09-19 02:33:21 +00:00
|
|
|
};
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
/**
|
2009-12-16 05:16:46 +00:00
|
|
|
* @brief Class with exception generation control. Intended to be
|
|
|
|
* used as a value_type in templatized code.
|
|
|
|
*
|
|
|
|
* Note: Destructor not allowed to throw.
|
|
|
|
*/
|
|
|
|
template<typename _Cond>
|
|
|
|
struct throw_value_base : public _Cond
|
|
|
|
{
|
|
|
|
typedef _Cond condition_type;
|
|
|
|
|
|
|
|
using condition_type::throw_conditionally;
|
|
|
|
|
|
|
|
std::size_t _M_i;
|
|
|
|
|
2010-01-01 03:38:58 +00:00
|
|
|
#ifndef _GLIBCXX_IS_AGGREGATE
|
2009-12-16 05:16:46 +00:00
|
|
|
throw_value_base() : _M_i(0)
|
|
|
|
{ throw_conditionally(); }
|
|
|
|
|
2010-01-01 03:38:58 +00:00
|
|
|
throw_value_base(const throw_value_base& __v) : _M_i(__v._M_i)
|
2009-12-16 05:16:46 +00:00
|
|
|
{ throw_conditionally(); }
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2012-11-05 20:58:35 +00:00
|
|
|
// Shall not throw.
|
|
|
|
throw_value_base(throw_value_base&&) = default;
|
|
|
|
#endif
|
|
|
|
|
2010-01-01 03:38:58 +00:00
|
|
|
explicit throw_value_base(const std::size_t __i) : _M_i(__i)
|
2009-12-16 05:16:46 +00:00
|
|
|
{ throw_conditionally(); }
|
2010-01-01 03:38:58 +00:00
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
throw_value_base&
|
|
|
|
operator=(const throw_value_base& __v)
|
|
|
|
{
|
|
|
|
throw_conditionally();
|
|
|
|
_M_i = __v._M_i;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2012-11-05 20:58:35 +00:00
|
|
|
// Shall not throw.
|
|
|
|
throw_value_base&
|
|
|
|
operator=(throw_value_base&&) = default;
|
|
|
|
#endif
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
throw_value_base&
|
|
|
|
operator++()
|
|
|
|
{
|
|
|
|
throw_conditionally();
|
|
|
|
++_M_i;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename _Cond>
|
|
|
|
inline void
|
|
|
|
swap(throw_value_base<_Cond>& __a, throw_value_base<_Cond>& __b)
|
|
|
|
{
|
|
|
|
typedef throw_value_base<_Cond> throw_value;
|
|
|
|
throw_value::throw_conditionally();
|
|
|
|
throw_value orig(__a);
|
|
|
|
__a = __b;
|
|
|
|
__b = orig;
|
|
|
|
}
|
|
|
|
|
|
|
|
// General instantiable types requirements.
|
|
|
|
template<typename _Cond>
|
|
|
|
inline bool
|
|
|
|
operator==(const throw_value_base<_Cond>& __a,
|
|
|
|
const throw_value_base<_Cond>& __b)
|
|
|
|
{
|
|
|
|
typedef throw_value_base<_Cond> throw_value;
|
|
|
|
throw_value::throw_conditionally();
|
|
|
|
bool __ret = __a._M_i == __b._M_i;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _Cond>
|
|
|
|
inline bool
|
|
|
|
operator<(const throw_value_base<_Cond>& __a,
|
|
|
|
const throw_value_base<_Cond>& __b)
|
|
|
|
{
|
|
|
|
typedef throw_value_base<_Cond> throw_value;
|
|
|
|
throw_value::throw_conditionally();
|
|
|
|
bool __ret = __a._M_i < __b._M_i;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Numeric algorithms instantiable types requirements.
|
|
|
|
template<typename _Cond>
|
|
|
|
inline throw_value_base<_Cond>
|
|
|
|
operator+(const throw_value_base<_Cond>& __a,
|
|
|
|
const throw_value_base<_Cond>& __b)
|
|
|
|
{
|
|
|
|
typedef throw_value_base<_Cond> throw_value;
|
|
|
|
throw_value::throw_conditionally();
|
|
|
|
throw_value __ret(__a._M_i + __b._M_i);
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _Cond>
|
|
|
|
inline throw_value_base<_Cond>
|
|
|
|
operator-(const throw_value_base<_Cond>& __a,
|
|
|
|
const throw_value_base<_Cond>& __b)
|
|
|
|
{
|
|
|
|
typedef throw_value_base<_Cond> throw_value;
|
|
|
|
throw_value::throw_conditionally();
|
|
|
|
throw_value __ret(__a._M_i - __b._M_i);
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _Cond>
|
|
|
|
inline throw_value_base<_Cond>
|
|
|
|
operator*(const throw_value_base<_Cond>& __a,
|
|
|
|
const throw_value_base<_Cond>& __b)
|
|
|
|
{
|
|
|
|
typedef throw_value_base<_Cond> throw_value;
|
|
|
|
throw_value::throw_conditionally();
|
|
|
|
throw_value __ret(__a._M_i * __b._M_i);
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
2010-01-01 03:38:58 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
/// Type throwing via limit condition.
|
|
|
|
struct throw_value_limit : public throw_value_base<limit_condition>
|
|
|
|
{
|
|
|
|
typedef throw_value_base<limit_condition> base_type;
|
|
|
|
|
2010-01-01 03:38:58 +00:00
|
|
|
#ifndef _GLIBCXX_IS_AGGREGATE
|
2009-12-16 05:16:46 +00:00
|
|
|
throw_value_limit() { }
|
|
|
|
|
|
|
|
throw_value_limit(const throw_value_limit& __other)
|
|
|
|
: base_type(__other._M_i) { }
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2012-11-05 20:58:35 +00:00
|
|
|
throw_value_limit(throw_value_limit&&) = default;
|
|
|
|
#endif
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
explicit throw_value_limit(const std::size_t __i) : base_type(__i) { }
|
2010-01-01 03:38:58 +00:00
|
|
|
#endif
|
2012-11-05 20:58:35 +00:00
|
|
|
|
|
|
|
throw_value_limit&
|
|
|
|
operator=(const throw_value_limit& __other)
|
|
|
|
{
|
|
|
|
base_type::operator=(__other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2012-11-05 20:58:35 +00:00
|
|
|
throw_value_limit&
|
|
|
|
operator=(throw_value_limit&&) = default;
|
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Type throwing via random condition.
|
|
|
|
struct throw_value_random : public throw_value_base<random_condition>
|
|
|
|
{
|
|
|
|
typedef throw_value_base<random_condition> base_type;
|
|
|
|
|
2010-01-01 03:38:58 +00:00
|
|
|
#ifndef _GLIBCXX_IS_AGGREGATE
|
2009-12-16 05:16:46 +00:00
|
|
|
throw_value_random() { }
|
|
|
|
|
|
|
|
throw_value_random(const throw_value_random& __other)
|
|
|
|
: base_type(__other._M_i) { }
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2012-11-05 20:58:35 +00:00
|
|
|
throw_value_random(throw_value_random&&) = default;
|
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
explicit throw_value_random(const std::size_t __i) : base_type(__i) { }
|
2010-01-01 03:38:58 +00:00
|
|
|
#endif
|
2012-11-05 20:58:35 +00:00
|
|
|
|
|
|
|
throw_value_random&
|
|
|
|
operator=(const throw_value_random& __other)
|
|
|
|
{
|
|
|
|
base_type::operator=(__other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2012-11-05 20:58:35 +00:00
|
|
|
throw_value_random&
|
|
|
|
operator=(throw_value_random&&) = default;
|
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocator class with logging and exception generation control.
|
|
|
|
* Intended to be used as an allocator_type in templatized code.
|
2009-02-21 00:45:21 +00:00
|
|
|
* @ingroup allocators
|
2009-12-16 05:16:46 +00:00
|
|
|
*
|
|
|
|
* Note: Deallocate not allowed to throw.
|
2009-02-21 00:45:21 +00:00
|
|
|
*/
|
2009-12-16 05:16:46 +00:00
|
|
|
template<typename _Tp, typename _Cond>
|
|
|
|
class throw_allocator_base
|
|
|
|
: public annotate_base, public _Cond
|
2006-09-19 02:33:21 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-10-23 17:14:47 +01:00
|
|
|
typedef std::size_t size_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
2009-12-16 05:16:46 +00:00
|
|
|
typedef _Tp value_type;
|
2006-09-28 01:23:58 +00:00
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef const value_type* const_pointer;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
|
|
|
|
2012-11-19 22:28:00 +00:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 2103. std::allocator propagate_on_container_move_assignment
|
|
|
|
typedef std::true_type propagate_on_container_move_assignment;
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
private:
|
2009-12-16 05:16:46 +00:00
|
|
|
typedef _Cond condition_type;
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
std::allocator<value_type> _M_allocator;
|
2006-09-19 02:33:21 +00:00
|
|
|
|
Remove redundant std::allocator members for C++20
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.
Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.
* include/bits/alloc_traits.h
(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
(allocator_traits<allocator<T>>::construct): Perform placement new
directly for C++20, instead of calling allocator<T>::construct.
(allocator_traits<allocator<T>>::destroy): Call destructor directly
for C++20, instead of calling allocator<T>::destroy.
(allocator_traits<allocator<T>>::max_size): Return value directly
for C++20, instead of calling std::allocator<T>::max_size().
(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
define for C++17 and up.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
for C++17 and up, instead of tag dispatching.
* include/bits/allocator.h (allocator<void>): Remove for C++20.
(allocator::pointer, allocator::const_pointer, allocator::reference)
(allocator::const_reference, allocator::rebind): Remove for C++20.
* include/bits/basic_string.h (basic_string): Use __alloc_traits to
rebind allocator.
* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
(malloc_allocator::pointer, malloc_allocator::const_pointer)
(malloc_allocator::reference, malloc_allocator::const_reference)
(malloc_allocator::rebind, malloc_allocator::max_size)
(malloc_allocator::construct, malloc_allocator::destroy): Do not
define for C++20.
(malloc_allocator::_M_max_size): Define new function.
* include/ext/new_allocator.h (new_allocator::~new_allocator)
(new_allocator::pointer, new_allocator::const_pointer)
(new_allocator::reference, new_allocator::const_reference)
(new_allocator::rebind, new_allocator::max_size)
(new_allocator::construct, new_allocator::destroy): Do not
define for C++20.
(new_allocator::_M_max_size): Define new function.
* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
__alloc_traits to rebind allocator.
* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
to construct character.
* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
allocator.
* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
Use __alloc_traits.
* include/ext/throw_allocator.h (throw_allocator): Do not use optional
members of std::allocator, use __alloc_traits members instead.
* include/ext/vstring.h (__versa_string): Use __alloc_traits.
* include/ext/vstring_util.h (__vstring_utility): Likewise.
* include/std/memory: Include <bits/alloc_traits.h>.
* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
* testsuite/20_util/allocator/rebind_c++20.cc: New test.
* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
for pointer, const_pointer, reference, const_reference or rebind in
C++20.
* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
* testsuite/23_containers/deque/capacity/29134.cc: Use
__gnu_test::max_size.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/list/capacity/29134.cc: Likewise.
* testsuite/23_containers/map/capacity/29134.cc: Likewise.
* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
* testsuite/23_containers/set/capacity/29134.cc: Likewise.
* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
test for C++20.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
* testsuite/util/replacement_memory_operators.h: Do not assume
Alloc::pointer exists.
* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
helper to call max_size for any allocator.
From-SVN: r277300
2019-10-22 22:48:39 +01:00
|
|
|
typedef __gnu_cxx::__alloc_traits<std::allocator<value_type> > traits;
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
using condition_type::throw_conditionally;
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
public:
|
2006-09-19 02:33:21 +00:00
|
|
|
size_type
|
2011-06-10 17:14:40 +00:00
|
|
|
max_size() const _GLIBCXX_USE_NOEXCEPT
|
Remove redundant std::allocator members for C++20
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.
Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.
* include/bits/alloc_traits.h
(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
(allocator_traits<allocator<T>>::construct): Perform placement new
directly for C++20, instead of calling allocator<T>::construct.
(allocator_traits<allocator<T>>::destroy): Call destructor directly
for C++20, instead of calling allocator<T>::destroy.
(allocator_traits<allocator<T>>::max_size): Return value directly
for C++20, instead of calling std::allocator<T>::max_size().
(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
define for C++17 and up.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
for C++17 and up, instead of tag dispatching.
* include/bits/allocator.h (allocator<void>): Remove for C++20.
(allocator::pointer, allocator::const_pointer, allocator::reference)
(allocator::const_reference, allocator::rebind): Remove for C++20.
* include/bits/basic_string.h (basic_string): Use __alloc_traits to
rebind allocator.
* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
(malloc_allocator::pointer, malloc_allocator::const_pointer)
(malloc_allocator::reference, malloc_allocator::const_reference)
(malloc_allocator::rebind, malloc_allocator::max_size)
(malloc_allocator::construct, malloc_allocator::destroy): Do not
define for C++20.
(malloc_allocator::_M_max_size): Define new function.
* include/ext/new_allocator.h (new_allocator::~new_allocator)
(new_allocator::pointer, new_allocator::const_pointer)
(new_allocator::reference, new_allocator::const_reference)
(new_allocator::rebind, new_allocator::max_size)
(new_allocator::construct, new_allocator::destroy): Do not
define for C++20.
(new_allocator::_M_max_size): Define new function.
* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
__alloc_traits to rebind allocator.
* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
to construct character.
* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
allocator.
* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
Use __alloc_traits.
* include/ext/throw_allocator.h (throw_allocator): Do not use optional
members of std::allocator, use __alloc_traits members instead.
* include/ext/vstring.h (__versa_string): Use __alloc_traits.
* include/ext/vstring_util.h (__vstring_utility): Likewise.
* include/std/memory: Include <bits/alloc_traits.h>.
* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
* testsuite/20_util/allocator/rebind_c++20.cc: New test.
* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
for pointer, const_pointer, reference, const_reference or rebind in
C++20.
* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
* testsuite/23_containers/deque/capacity/29134.cc: Use
__gnu_test::max_size.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/list/capacity/29134.cc: Likewise.
* testsuite/23_containers/map/capacity/29134.cc: Likewise.
* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
* testsuite/23_containers/set/capacity/29134.cc: Likewise.
* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
test for C++20.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
* testsuite/util/replacement_memory_operators.h: Do not assume
Alloc::pointer exists.
* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
helper to call max_size for any allocator.
From-SVN: r277300
2019-10-22 22:48:39 +01:00
|
|
|
{ return traits::max_size(_M_allocator); }
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2010-05-20 22:35:49 +00:00
|
|
|
pointer
|
2011-06-10 17:14:40 +00:00
|
|
|
address(reference __x) const _GLIBCXX_NOEXCEPT
|
|
|
|
{ return std::__addressof(__x); }
|
2010-05-20 22:35:49 +00:00
|
|
|
|
|
|
|
const_pointer
|
2011-06-10 17:14:40 +00:00
|
|
|
address(const_reference __x) const _GLIBCXX_NOEXCEPT
|
|
|
|
{ return std::__addressof(__x); }
|
2010-05-20 22:35:49 +00:00
|
|
|
|
2019-01-21 11:47:30 +00:00
|
|
|
_GLIBCXX_NODISCARD pointer
|
2023-02-16 11:32:00 +00:00
|
|
|
allocate(size_type __n, const void* __hint = 0)
|
2006-09-19 02:33:21 +00:00
|
|
|
{
|
2009-04-24 11:35:19 +02:00
|
|
|
if (__n > this->max_size())
|
2007-06-01 10:09:40 +00:00
|
|
|
std::__throw_bad_alloc();
|
|
|
|
|
2006-09-19 02:33:21 +00:00
|
|
|
throw_conditionally();
|
2023-02-16 11:32:00 +00:00
|
|
|
pointer const a = traits::allocate(_M_allocator, __n, __hint);
|
2007-06-01 10:09:40 +00:00
|
|
|
insert(a, sizeof(value_type) * __n);
|
2006-09-19 02:33:21 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2011-05-28 13:27:43 +00:00
|
|
|
template<typename _Up, typename... _Args>
|
|
|
|
void
|
|
|
|
construct(_Up* __p, _Args&&... __args)
|
2013-04-22 20:22:07 +00:00
|
|
|
{
|
Remove redundant std::allocator members for C++20
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.
Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.
* include/bits/alloc_traits.h
(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
(allocator_traits<allocator<T>>::construct): Perform placement new
directly for C++20, instead of calling allocator<T>::construct.
(allocator_traits<allocator<T>>::destroy): Call destructor directly
for C++20, instead of calling allocator<T>::destroy.
(allocator_traits<allocator<T>>::max_size): Return value directly
for C++20, instead of calling std::allocator<T>::max_size().
(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
define for C++17 and up.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
for C++17 and up, instead of tag dispatching.
* include/bits/allocator.h (allocator<void>): Remove for C++20.
(allocator::pointer, allocator::const_pointer, allocator::reference)
(allocator::const_reference, allocator::rebind): Remove for C++20.
* include/bits/basic_string.h (basic_string): Use __alloc_traits to
rebind allocator.
* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
(malloc_allocator::pointer, malloc_allocator::const_pointer)
(malloc_allocator::reference, malloc_allocator::const_reference)
(malloc_allocator::rebind, malloc_allocator::max_size)
(malloc_allocator::construct, malloc_allocator::destroy): Do not
define for C++20.
(malloc_allocator::_M_max_size): Define new function.
* include/ext/new_allocator.h (new_allocator::~new_allocator)
(new_allocator::pointer, new_allocator::const_pointer)
(new_allocator::reference, new_allocator::const_reference)
(new_allocator::rebind, new_allocator::max_size)
(new_allocator::construct, new_allocator::destroy): Do not
define for C++20.
(new_allocator::_M_max_size): Define new function.
* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
__alloc_traits to rebind allocator.
* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
to construct character.
* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
allocator.
* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
Use __alloc_traits.
* include/ext/throw_allocator.h (throw_allocator): Do not use optional
members of std::allocator, use __alloc_traits members instead.
* include/ext/vstring.h (__versa_string): Use __alloc_traits.
* include/ext/vstring_util.h (__vstring_utility): Likewise.
* include/std/memory: Include <bits/alloc_traits.h>.
* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
* testsuite/20_util/allocator/rebind_c++20.cc: New test.
* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
for pointer, const_pointer, reference, const_reference or rebind in
C++20.
* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
* testsuite/23_containers/deque/capacity/29134.cc: Use
__gnu_test::max_size.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/list/capacity/29134.cc: Likewise.
* testsuite/23_containers/map/capacity/29134.cc: Likewise.
* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
* testsuite/23_containers/set/capacity/29134.cc: Likewise.
* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
test for C++20.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
* testsuite/util/replacement_memory_operators.h: Do not assume
Alloc::pointer exists.
* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
helper to call max_size for any allocator.
From-SVN: r277300
2019-10-22 22:48:39 +01:00
|
|
|
traits::construct(_M_allocator, __p, std::forward<_Args>(__args)...);
|
2013-04-22 20:22:07 +00:00
|
|
|
insert_construct(__p);
|
|
|
|
}
|
2011-05-28 13:27:43 +00:00
|
|
|
|
|
|
|
template<typename _Up>
|
|
|
|
void
|
|
|
|
destroy(_Up* __p)
|
2013-04-22 20:22:07 +00:00
|
|
|
{
|
|
|
|
erase_construct(__p);
|
Remove redundant std::allocator members for C++20
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.
Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.
* include/bits/alloc_traits.h
(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
(allocator_traits<allocator<T>>::construct): Perform placement new
directly for C++20, instead of calling allocator<T>::construct.
(allocator_traits<allocator<T>>::destroy): Call destructor directly
for C++20, instead of calling allocator<T>::destroy.
(allocator_traits<allocator<T>>::max_size): Return value directly
for C++20, instead of calling std::allocator<T>::max_size().
(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
define for C++17 and up.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
for C++17 and up, instead of tag dispatching.
* include/bits/allocator.h (allocator<void>): Remove for C++20.
(allocator::pointer, allocator::const_pointer, allocator::reference)
(allocator::const_reference, allocator::rebind): Remove for C++20.
* include/bits/basic_string.h (basic_string): Use __alloc_traits to
rebind allocator.
* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
(malloc_allocator::pointer, malloc_allocator::const_pointer)
(malloc_allocator::reference, malloc_allocator::const_reference)
(malloc_allocator::rebind, malloc_allocator::max_size)
(malloc_allocator::construct, malloc_allocator::destroy): Do not
define for C++20.
(malloc_allocator::_M_max_size): Define new function.
* include/ext/new_allocator.h (new_allocator::~new_allocator)
(new_allocator::pointer, new_allocator::const_pointer)
(new_allocator::reference, new_allocator::const_reference)
(new_allocator::rebind, new_allocator::max_size)
(new_allocator::construct, new_allocator::destroy): Do not
define for C++20.
(new_allocator::_M_max_size): Define new function.
* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
__alloc_traits to rebind allocator.
* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
to construct character.
* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
allocator.
* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
Use __alloc_traits.
* include/ext/throw_allocator.h (throw_allocator): Do not use optional
members of std::allocator, use __alloc_traits members instead.
* include/ext/vstring.h (__versa_string): Use __alloc_traits.
* include/ext/vstring_util.h (__vstring_utility): Likewise.
* include/std/memory: Include <bits/alloc_traits.h>.
* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
* testsuite/20_util/allocator/rebind_c++20.cc: New test.
* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
for pointer, const_pointer, reference, const_reference or rebind in
C++20.
* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
* testsuite/23_containers/deque/capacity/29134.cc: Use
__gnu_test::max_size.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/list/capacity/29134.cc: Likewise.
* testsuite/23_containers/map/capacity/29134.cc: Likewise.
* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
* testsuite/23_containers/set/capacity/29134.cc: Likewise.
* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
test for C++20.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
* testsuite/util/replacement_memory_operators.h: Do not assume
Alloc::pointer exists.
* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
helper to call max_size for any allocator.
From-SVN: r277300
2019-10-22 22:48:39 +01:00
|
|
|
traits::destroy(_M_allocator, __p);
|
2013-04-22 20:22:07 +00:00
|
|
|
}
|
2011-05-28 13:27:43 +00:00
|
|
|
#else
|
2006-09-19 02:33:21 +00:00
|
|
|
void
|
2023-02-16 11:32:00 +00:00
|
|
|
construct(pointer __p, const value_type& __val)
|
|
|
|
{ return _M_allocator.construct(__p, __val); }
|
2006-09-19 02:33:21 +00:00
|
|
|
|
|
|
|
void
|
2007-06-01 10:09:40 +00:00
|
|
|
destroy(pointer __p)
|
2009-06-05 08:45:26 +00:00
|
|
|
{ _M_allocator.destroy(__p); }
|
2011-05-28 13:27:43 +00:00
|
|
|
#endif
|
2006-09-19 02:33:21 +00:00
|
|
|
|
|
|
|
void
|
2007-06-01 10:09:40 +00:00
|
|
|
deallocate(pointer __p, size_type __n)
|
2006-09-19 02:33:21 +00:00
|
|
|
{
|
2007-06-01 10:09:40 +00:00
|
|
|
erase(__p, sizeof(value_type) * __n);
|
2009-06-05 08:45:26 +00:00
|
|
|
_M_allocator.deallocate(__p, __n);
|
2006-09-19 02:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-01 10:09:40 +00:00
|
|
|
check_allocated(pointer __p, size_type __n)
|
2009-06-05 08:45:26 +00:00
|
|
|
{
|
|
|
|
size_type __t = sizeof(value_type) * __n;
|
|
|
|
annotate_base::check_allocated(__p, __t);
|
|
|
|
}
|
2006-09-28 01:23:58 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
void
|
2013-04-22 20:22:07 +00:00
|
|
|
check(size_type __n)
|
|
|
|
{ annotate_base::check(__n); }
|
2009-12-16 05:16:46 +00:00
|
|
|
};
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
template<typename _Tp, typename _Cond>
|
2006-09-19 02:33:21 +00:00
|
|
|
inline bool
|
2009-12-16 05:16:46 +00:00
|
|
|
operator==(const throw_allocator_base<_Tp, _Cond>&,
|
|
|
|
const throw_allocator_base<_Tp, _Cond>&)
|
2006-09-19 02:33:21 +00:00
|
|
|
{ return true; }
|
|
|
|
|
2020-04-15 19:47:48 +01:00
|
|
|
#if __cpp_impl_three_way_comparison < 201907L
|
2009-12-16 05:16:46 +00:00
|
|
|
template<typename _Tp, typename _Cond>
|
2006-09-19 02:33:21 +00:00
|
|
|
inline bool
|
2009-12-16 05:16:46 +00:00
|
|
|
operator!=(const throw_allocator_base<_Tp, _Cond>&,
|
|
|
|
const throw_allocator_base<_Tp, _Cond>&)
|
2006-09-19 02:33:21 +00:00
|
|
|
{ return false; }
|
2020-04-15 19:47:48 +01:00
|
|
|
#endif
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
/// Allocator throwing via limit condition.
|
|
|
|
template<typename _Tp>
|
|
|
|
struct throw_allocator_limit
|
|
|
|
: public throw_allocator_base<_Tp, limit_condition>
|
|
|
|
{
|
|
|
|
template<typename _Tp1>
|
|
|
|
struct rebind
|
|
|
|
{ typedef throw_allocator_limit<_Tp1> other; };
|
|
|
|
|
2011-06-10 17:14:40 +00:00
|
|
|
throw_allocator_limit() _GLIBCXX_USE_NOEXCEPT { }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2011-06-10 17:14:40 +00:00
|
|
|
throw_allocator_limit(const throw_allocator_limit&)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT { }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
template<typename _Tp1>
|
2011-06-10 17:14:40 +00:00
|
|
|
throw_allocator_limit(const throw_allocator_limit<_Tp1>&)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT { }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2011-06-10 17:14:40 +00:00
|
|
|
~throw_allocator_limit() _GLIBCXX_USE_NOEXCEPT { }
|
2020-10-29 11:43:55 +00:00
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
throw_allocator_limit&
|
|
|
|
operator=(const throw_allocator_limit&) = default;
|
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Allocator throwing via random condition.
|
|
|
|
template<typename _Tp>
|
|
|
|
struct throw_allocator_random
|
|
|
|
: public throw_allocator_base<_Tp, random_condition>
|
|
|
|
{
|
|
|
|
template<typename _Tp1>
|
|
|
|
struct rebind
|
|
|
|
{ typedef throw_allocator_random<_Tp1> other; };
|
|
|
|
|
2011-06-10 17:14:40 +00:00
|
|
|
throw_allocator_random() _GLIBCXX_USE_NOEXCEPT { }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2011-06-10 17:14:40 +00:00
|
|
|
throw_allocator_random(const throw_allocator_random&)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT { }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
template<typename _Tp1>
|
2011-06-10 17:14:40 +00:00
|
|
|
throw_allocator_random(const throw_allocator_random<_Tp1>&)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT { }
|
2009-12-16 05:16:46 +00:00
|
|
|
|
2011-06-10 17:14:40 +00:00
|
|
|
~throw_allocator_random() _GLIBCXX_USE_NOEXCEPT { }
|
2020-10-29 11:43:55 +00:00
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
throw_allocator_random&
|
|
|
|
operator=(const throw_allocator_random&) = default;
|
|
|
|
#endif
|
2009-12-16 05:16:46 +00:00
|
|
|
};
|
|
|
|
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 22:39:36 +00:00
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
|
|
} // namespace
|
2006-09-19 02:33:21 +00:00
|
|
|
|
2012-11-10 12:27:22 -05:00
|
|
|
#if __cplusplus >= 201103L
|
2009-12-16 05:16:46 +00:00
|
|
|
|
|
|
|
# include <bits/functional_hash.h>
|
|
|
|
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 22:39:36 +00:00
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
2009-12-16 05:16:46 +00:00
|
|
|
{
|
libstdc++: Add attribute to features deprecated in C++17 [PR91260]
There are a lot of things in the C++ standard library which were
deprecated in C++11, and more in C++17. Some of them were removed after
deprecation and are no longer present in the standard at all. We have
not removed these from libstdc++ because keeping them as non-standard
extensions is conforming, and avoids gratuitously breaking user code,
and in some cases we need to keep using them to avoid ABI changes. But
we should at least give a warning for using them. That has not been done
previously because of the library's own uses of them (e.g. the
std::iterator class template used as a base class).
This adds deprecated attributes to the relevant components, and then
goes through the whole library to add diagnostic pragmas where needed to
suppress warnings about our internal uses of them. The tests are updated
to either expect the additional warnings, or to suppress them where we
aren't interested in them.
libstdc++-v3/ChangeLog:
PR libstdc++/91260
PR libstdc++/91383
PR libstdc++/95065
* include/backward/binders.h (bind1st, bind2nd): Add deprecated
attribute.
* include/bits/refwrap.h (_Maybe_unary_or_binary_function):
Disable deprecated warnings for base classes.
(_Reference_wrapper_base): Likewise.
* include/bits/shared_ptr_base.h (_Sp_owner_less): Likewise.
* include/bits/stl_bvector.h (_Bit_iterator_base): Likewise.
* include/bits/stl_function.h (unary_function, binary_function):
Add deprecated attribute.
(unary_negate, not1, binary_negate, not2, ptr_fun)
(pointer_to_unary_function, pointer_to_binary_function)
(mem_fun_t, const_mem_fun_t, mem_fun_ref_t, const_mem_fun_ref_t)
(mem_fun1_t, const_mem_fun1_t, mem_fun_ref1_t)
(const_mem_fun1_ref_t, mem_fun, mem_fun_ref): Add deprecated
attributes.
* include/bits/stl_iterator.h: Disable deprecated warnings for
std::iterator base classes.
* include/bits/stl_iterator_base_types.h (iterator): Add
deprecated attribute.
* include/bits/stl_map.h (map::value_compare): Disable
deprecated warnings for base class.
* include/bits/stl_multimap.h (multimap::value_compare):
Likewise.
* include/bits/stl_raw_storage_iter.h (raw_storage_iterator):
Add deprecated attribute.
* include/bits/stl_tempbuf.h (get_temporary_buffer): Likewise.
* include/bits/stream_iterator.h: Disable deprecated warnings.
* include/bits/streambuf_iterator.h: Likewise.
* include/ext/bitmap_allocator.h: Remove unary_function base
classes.
* include/ext/functional: Disable deprecated warnings.
* include/ext/rope: Likewise.
* include/ext/throw_allocator.h: Likewise.
* include/std/type_traits (result_of): Add deprecated attribute.
* include/tr1/functional: Disable deprecated warnings.
* include/tr1/functional_hash.h: Likewise.
* testsuite/20_util/function_objects/binders/1.cc: Add
-Wno-disable-deprecations.
* testsuite/20_util/function_objects/binders/3113.cc: Likewise.
* testsuite/20_util/function_objects/constexpr.cc: Add
dg-warning.
* testsuite/20_util/raw_storage_iterator/base.cc: Likewise.
* testsuite/20_util/raw_storage_iterator/dr2127.cc: Likewise.
* testsuite/20_util/raw_storage_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/20_util/raw_storage_iterator/requirements/explicit_instantiation/1.cc:
Likewise.
* testsuite/20_util/raw_storage_iterator/requirements/typedefs.cc:
Likewise.
* testsuite/20_util/reference_wrapper/24803.cc:
Likewise.
* testsuite/20_util/reference_wrapper/typedefs.cc: Enable for
C++20 and check for absence of nested types.
* testsuite/20_util/shared_ptr/comparison/less.cc: Remove
std::binary_function base class.
* testsuite/20_util/temporary_buffer.cc: Add dg-warning.
* testsuite/21_strings/basic_string/cons/char/69092.cc: Remove
std::iterator base class.
* testsuite/24_iterators/back_insert_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/front_insert_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/insert_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/istream_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/istreambuf_iterator/92285.cc:
Likewise.
* testsuite/24_iterators/istreambuf_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/ostream_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/ostreambuf_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/reverse_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/25_algorithms/copy/34595.cc:
Likewise.
* testsuite/25_algorithms/minmax/3.cc: Remove std::binary_function
base class.
* testsuite/25_algorithms/all_of/requirements/explicit_instantiation/2.cc:
Disable deprecated warnings.
* testsuite/25_algorithms/all_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/any_of/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/any_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/count_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/count_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_end/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_end/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_first_of/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_first_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_if_not/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_if_not/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/for_each/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/for_each/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/is_partitioned/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/is_partitioned/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/is_permutation/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/is_permutation/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/none_of/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/none_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/partition/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/partition/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/partition_copy/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/partition_copy/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/partition_point/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/partition_point/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/remove_copy_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/remove_copy_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/remove_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/remove_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/replace_copy_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/replace_copy_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/replace_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/replace_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/search/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/search/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/search_n/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/search_n/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/transform/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/transform/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc: Add
dg-warning.
* testsuite/ext/pb_ds/example/priority_queue_erase_if.cc:
Likewise.
* testsuite/ext/pb_ds/example/priority_queue_split_join.cc:
Likewise.
* testsuite/tr1/3_function_objects/reference_wrapper/typedefs.cc:
Disable deprecated warnings.
* testsuite/tr1/6_containers/hash/requirements/base_classes.cc:
Likewise.
* testsuite/util/regression/trait/erase_if_fn.hpp: Remove
std::unary_function base classes.
* testsuite/util/testsuite_iterators.h (output_iterator_wrapper):
Remove std::iterator base classes.
2022-01-11 18:42:38 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
|
2009-12-16 05:16:46 +00:00
|
|
|
/// Explicit specialization of std::hash for __gnu_cxx::throw_value_limit.
|
|
|
|
template<>
|
|
|
|
struct hash<__gnu_cxx::throw_value_limit>
|
|
|
|
: public std::unary_function<__gnu_cxx::throw_value_limit, size_t>
|
|
|
|
{
|
|
|
|
size_t
|
testsuite_container_traits.h (traits_base): Add has_throwing_erase trait.
2010-03-04 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/util/testsuite_container_traits.h (traits_base): Add
has_throwing_erase trait.
(traits<vector>, traits<deque>): Typedef the latter to true_type.
* testsuite/util/exception/safety.h (generation_prohibited):
Do not test vector::erase and deque::erase: can throw if
either copy constructor or assignment operator of value_type
throws.
* testsuite/23_containers/vector/requirements/exception/
generation_prohibited.cc: Remove xfail.
* testsuite/23_containers/deque/requirements/exception/
generation_prohibited.cc: Likewise.
* include/ext/throw_allocator.h (hash<__gnu_cxx::throw_value_limit>::
operator(), hash<__gnu_cxx::throw_value_random>::operator()): Pass
argument by const ref.
* testsuite/util/testsuite_container_traits.h (traits<map>,
traits<multimap>, traits<set>, traits<multiset>,
traits<unordered_map>, traits<unordered_multimap>,
traits<unordered_set>, traits<unordered_multiset>): Typedef
consistently has_erase and has_insert as true_type.
* testsuite/util/testsuite_container_traits.h
(traits<unordered_map>, traits<unordered_multimap>,
traits<unordered_set>, traits<unordered_multiset>): Do not wrongly
typedef has_size_type_constructor as true_type: the constructor
accepting a size_type actually gets the initial number of
buckets.
From-SVN: r157239
2010-03-05 01:51:56 +00:00
|
|
|
operator()(const __gnu_cxx::throw_value_limit& __val) const
|
2009-12-16 05:16:46 +00:00
|
|
|
{
|
2013-04-22 20:22:07 +00:00
|
|
|
__gnu_cxx::throw_value_limit::throw_conditionally();
|
2010-09-19 09:44:24 +00:00
|
|
|
std::hash<std::size_t> __h;
|
|
|
|
size_t __result = __h(__val._M_i);
|
2009-12-16 05:16:46 +00:00
|
|
|
return __result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-22 20:22:07 +00:00
|
|
|
/// Explicit specialization of std::hash for __gnu_cxx::throw_value_random.
|
2009-12-16 05:16:46 +00:00
|
|
|
template<>
|
|
|
|
struct hash<__gnu_cxx::throw_value_random>
|
|
|
|
: public std::unary_function<__gnu_cxx::throw_value_random, size_t>
|
|
|
|
{
|
|
|
|
size_t
|
testsuite_container_traits.h (traits_base): Add has_throwing_erase trait.
2010-03-04 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/util/testsuite_container_traits.h (traits_base): Add
has_throwing_erase trait.
(traits<vector>, traits<deque>): Typedef the latter to true_type.
* testsuite/util/exception/safety.h (generation_prohibited):
Do not test vector::erase and deque::erase: can throw if
either copy constructor or assignment operator of value_type
throws.
* testsuite/23_containers/vector/requirements/exception/
generation_prohibited.cc: Remove xfail.
* testsuite/23_containers/deque/requirements/exception/
generation_prohibited.cc: Likewise.
* include/ext/throw_allocator.h (hash<__gnu_cxx::throw_value_limit>::
operator(), hash<__gnu_cxx::throw_value_random>::operator()): Pass
argument by const ref.
* testsuite/util/testsuite_container_traits.h (traits<map>,
traits<multimap>, traits<set>, traits<multiset>,
traits<unordered_map>, traits<unordered_multimap>,
traits<unordered_set>, traits<unordered_multiset>): Typedef
consistently has_erase and has_insert as true_type.
* testsuite/util/testsuite_container_traits.h
(traits<unordered_map>, traits<unordered_multimap>,
traits<unordered_set>, traits<unordered_multiset>): Do not wrongly
typedef has_size_type_constructor as true_type: the constructor
accepting a size_type actually gets the initial number of
buckets.
From-SVN: r157239
2010-03-05 01:51:56 +00:00
|
|
|
operator()(const __gnu_cxx::throw_value_random& __val) const
|
2009-12-16 05:16:46 +00:00
|
|
|
{
|
2013-04-22 20:22:07 +00:00
|
|
|
__gnu_cxx::throw_value_random::throw_conditionally();
|
2010-09-19 09:44:24 +00:00
|
|
|
std::hash<std::size_t> __h;
|
|
|
|
size_t __result = __h(__val._M_i);
|
2009-12-16 05:16:46 +00:00
|
|
|
return __result;
|
|
|
|
}
|
|
|
|
};
|
libstdc++: Add attribute to features deprecated in C++17 [PR91260]
There are a lot of things in the C++ standard library which were
deprecated in C++11, and more in C++17. Some of them were removed after
deprecation and are no longer present in the standard at all. We have
not removed these from libstdc++ because keeping them as non-standard
extensions is conforming, and avoids gratuitously breaking user code,
and in some cases we need to keep using them to avoid ABI changes. But
we should at least give a warning for using them. That has not been done
previously because of the library's own uses of them (e.g. the
std::iterator class template used as a base class).
This adds deprecated attributes to the relevant components, and then
goes through the whole library to add diagnostic pragmas where needed to
suppress warnings about our internal uses of them. The tests are updated
to either expect the additional warnings, or to suppress them where we
aren't interested in them.
libstdc++-v3/ChangeLog:
PR libstdc++/91260
PR libstdc++/91383
PR libstdc++/95065
* include/backward/binders.h (bind1st, bind2nd): Add deprecated
attribute.
* include/bits/refwrap.h (_Maybe_unary_or_binary_function):
Disable deprecated warnings for base classes.
(_Reference_wrapper_base): Likewise.
* include/bits/shared_ptr_base.h (_Sp_owner_less): Likewise.
* include/bits/stl_bvector.h (_Bit_iterator_base): Likewise.
* include/bits/stl_function.h (unary_function, binary_function):
Add deprecated attribute.
(unary_negate, not1, binary_negate, not2, ptr_fun)
(pointer_to_unary_function, pointer_to_binary_function)
(mem_fun_t, const_mem_fun_t, mem_fun_ref_t, const_mem_fun_ref_t)
(mem_fun1_t, const_mem_fun1_t, mem_fun_ref1_t)
(const_mem_fun1_ref_t, mem_fun, mem_fun_ref): Add deprecated
attributes.
* include/bits/stl_iterator.h: Disable deprecated warnings for
std::iterator base classes.
* include/bits/stl_iterator_base_types.h (iterator): Add
deprecated attribute.
* include/bits/stl_map.h (map::value_compare): Disable
deprecated warnings for base class.
* include/bits/stl_multimap.h (multimap::value_compare):
Likewise.
* include/bits/stl_raw_storage_iter.h (raw_storage_iterator):
Add deprecated attribute.
* include/bits/stl_tempbuf.h (get_temporary_buffer): Likewise.
* include/bits/stream_iterator.h: Disable deprecated warnings.
* include/bits/streambuf_iterator.h: Likewise.
* include/ext/bitmap_allocator.h: Remove unary_function base
classes.
* include/ext/functional: Disable deprecated warnings.
* include/ext/rope: Likewise.
* include/ext/throw_allocator.h: Likewise.
* include/std/type_traits (result_of): Add deprecated attribute.
* include/tr1/functional: Disable deprecated warnings.
* include/tr1/functional_hash.h: Likewise.
* testsuite/20_util/function_objects/binders/1.cc: Add
-Wno-disable-deprecations.
* testsuite/20_util/function_objects/binders/3113.cc: Likewise.
* testsuite/20_util/function_objects/constexpr.cc: Add
dg-warning.
* testsuite/20_util/raw_storage_iterator/base.cc: Likewise.
* testsuite/20_util/raw_storage_iterator/dr2127.cc: Likewise.
* testsuite/20_util/raw_storage_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/20_util/raw_storage_iterator/requirements/explicit_instantiation/1.cc:
Likewise.
* testsuite/20_util/raw_storage_iterator/requirements/typedefs.cc:
Likewise.
* testsuite/20_util/reference_wrapper/24803.cc:
Likewise.
* testsuite/20_util/reference_wrapper/typedefs.cc: Enable for
C++20 and check for absence of nested types.
* testsuite/20_util/shared_ptr/comparison/less.cc: Remove
std::binary_function base class.
* testsuite/20_util/temporary_buffer.cc: Add dg-warning.
* testsuite/21_strings/basic_string/cons/char/69092.cc: Remove
std::iterator base class.
* testsuite/24_iterators/back_insert_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/front_insert_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/insert_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/istream_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/istreambuf_iterator/92285.cc:
Likewise.
* testsuite/24_iterators/istreambuf_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/ostream_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/ostreambuf_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/24_iterators/reverse_iterator/requirements/base_classes.cc:
Likewise.
* testsuite/25_algorithms/copy/34595.cc:
Likewise.
* testsuite/25_algorithms/minmax/3.cc: Remove std::binary_function
base class.
* testsuite/25_algorithms/all_of/requirements/explicit_instantiation/2.cc:
Disable deprecated warnings.
* testsuite/25_algorithms/all_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/any_of/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/any_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/count_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/count_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_end/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_end/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_first_of/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_first_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/find_if_not/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/find_if_not/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/for_each/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/for_each/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/is_partitioned/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/is_partitioned/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/is_permutation/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/is_permutation/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/none_of/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/none_of/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/partition/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/partition/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/partition_copy/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/partition_copy/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/partition_point/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/partition_point/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/remove_copy_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/remove_copy_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/remove_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/remove_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/replace_copy_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/replace_copy_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/replace_if/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/replace_if/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/search/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/search/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/search_n/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/search_n/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/25_algorithms/transform/requirements/explicit_instantiation/2.cc:
Likewise.
* testsuite/25_algorithms/transform/requirements/explicit_instantiation/pod.cc:
Likewise.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc: Add
dg-warning.
* testsuite/ext/pb_ds/example/priority_queue_erase_if.cc:
Likewise.
* testsuite/ext/pb_ds/example/priority_queue_split_join.cc:
Likewise.
* testsuite/tr1/3_function_objects/reference_wrapper/typedefs.cc:
Disable deprecated warnings.
* testsuite/tr1/6_containers/hash/requirements/base_classes.cc:
Likewise.
* testsuite/util/regression/trait/erase_if_fn.hpp: Remove
std::unary_function base classes.
* testsuite/util/testsuite_iterators.h (output_iterator_wrapper):
Remove std::iterator base classes.
2022-01-11 18:42:38 +00:00
|
|
|
|
|
|
|
#pragma GCC diagnostic pop
|
2009-12-16 05:16:46 +00:00
|
|
|
} // end namespace std
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 08:45:26 +00:00
|
|
|
#endif
|