2003-01-14 12:56:56 +08:00
|
|
|
// -*- C++ -*-
|
2002-11-26 08:53:12 +08:00
|
|
|
// Testing allocator for the C++ library testsuite.
|
|
|
|
//
|
2011-06-11 01:14:40 +08:00
|
|
|
// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
2007-05-23 06:43:22 +08:00
|
|
|
// Free Software Foundation, Inc.
|
2002-11-26 08:53:12 +08: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
|
2009-04-09 23:00:19 +08:00
|
|
|
// Free Software Foundation; either version 3, or (at your option)
|
2002-11-26 08:53:12 +08:00
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
2009-04-09 23:00:19 +08:00
|
|
|
// with this library; see the file COPYING3. If not see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2002-11-26 08:53:12 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
// This file provides an test instrumentation allocator that can be
|
|
|
|
// used to verify allocation functionality of standard library
|
|
|
|
// containers. 2002.11.25 smw
|
|
|
|
|
2003-07-05 12:05:45 +08:00
|
|
|
#ifndef _GLIBCXX_TESTSUITE_ALLOCATOR_H
|
|
|
|
#define _GLIBCXX_TESTSUITE_ALLOCATOR_H
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
#include <tr1/unordered_map>
|
2008-06-22 00:55:17 +08:00
|
|
|
#include <bits/move.h>
|
2011-06-11 01:14:40 +08:00
|
|
|
#include <testsuite_hooks.h>
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2003-07-25 05:08:03 +08:00
|
|
|
namespace __gnu_test
|
2002-11-26 08:53:12 +08:00
|
|
|
{
|
2006-10-04 01:01:57 +08:00
|
|
|
class tracker_allocator_counter
|
2002-11-26 08:53:12 +08:00
|
|
|
{
|
2003-01-14 12:56:56 +08:00
|
|
|
public:
|
|
|
|
typedef std::size_t size_type;
|
|
|
|
|
|
|
|
static void*
|
|
|
|
allocate(size_type blocksize)
|
|
|
|
{
|
2006-10-04 01:01:57 +08:00
|
|
|
allocationCount_ += blocksize;
|
2003-01-14 12:56:56 +08:00
|
|
|
return ::operator new(blocksize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
construct() { constructCount_++; }
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2003-01-14 12:56:56 +08:00
|
|
|
static void
|
|
|
|
destroy() { destructCount_++; }
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2003-01-14 12:56:56 +08:00
|
|
|
static void
|
|
|
|
deallocate(void* p, size_type blocksize)
|
|
|
|
{
|
|
|
|
::operator delete(p);
|
2006-10-04 01:01:57 +08:00
|
|
|
deallocationCount_ += blocksize;
|
2003-01-14 12:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_type
|
2006-10-04 01:01:57 +08:00
|
|
|
get_allocation_count() { return allocationCount_; }
|
2003-01-14 12:56:56 +08:00
|
|
|
|
|
|
|
static size_type
|
2006-10-04 01:01:57 +08:00
|
|
|
get_deallocation_count() { return deallocationCount_; }
|
2003-01-14 12:56:56 +08:00
|
|
|
|
|
|
|
static int
|
2006-10-04 01:01:57 +08:00
|
|
|
get_construct_count() { return constructCount_; }
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2003-01-14 12:56:56 +08:00
|
|
|
static int
|
2006-10-04 01:01:57 +08:00
|
|
|
get_destruct_count() { return destructCount_; }
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2003-01-14 12:56:56 +08:00
|
|
|
static void
|
2006-10-04 01:01:57 +08:00
|
|
|
reset()
|
2003-01-14 12:56:56 +08:00
|
|
|
{
|
2006-10-04 01:01:57 +08:00
|
|
|
allocationCount_ = 0;
|
|
|
|
deallocationCount_ = 0;
|
2003-01-14 12:56:56 +08:00
|
|
|
constructCount_ = 0;
|
2006-10-04 01:01:57 +08:00
|
|
|
destructCount_ = 0;
|
2003-01-14 12:56:56 +08:00
|
|
|
}
|
2002-11-26 08:53:12 +08:00
|
|
|
|
|
|
|
private:
|
2006-10-04 01:01:57 +08:00
|
|
|
static size_type allocationCount_;
|
|
|
|
static size_type deallocationCount_;
|
2003-01-14 12:56:56 +08:00
|
|
|
static int constructCount_;
|
|
|
|
static int destructCount_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A simple basic allocator that just forwards to the
|
2006-10-04 01:01:57 +08:00
|
|
|
// tracker_allocator_counter to fulfill memory requests. This class
|
|
|
|
// is templated on the target object type, but tracker isn't.
|
2003-01-14 12:56:56 +08:00
|
|
|
template<class T>
|
2006-10-04 01:01:57 +08:00
|
|
|
class tracker_allocator
|
2002-11-26 08:53:12 +08:00
|
|
|
{
|
2006-10-04 01:01:57 +08:00
|
|
|
private:
|
|
|
|
typedef tracker_allocator_counter counter_type;
|
|
|
|
|
2002-11-26 08:53:12 +08:00
|
|
|
public:
|
|
|
|
typedef T value_type;
|
|
|
|
typedef T* pointer;
|
|
|
|
typedef const T* const_pointer;
|
|
|
|
typedef T& reference;
|
|
|
|
typedef const T& const_reference;
|
|
|
|
typedef std::size_t size_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
|
2006-10-04 01:01:57 +08:00
|
|
|
template<class U> struct rebind { typedef tracker_allocator<U> other; };
|
2002-11-26 08:53:12 +08:00
|
|
|
|
|
|
|
pointer
|
2011-06-11 01:14:40 +08:00
|
|
|
address(reference value) const _GLIBCXX_NOEXCEPT
|
|
|
|
{ return std::__addressof(value); }
|
|
|
|
|
2002-11-26 08:53:12 +08:00
|
|
|
const_pointer
|
2011-06-11 01:14:40 +08:00
|
|
|
address(const_reference value) const _GLIBCXX_NOEXCEPT
|
|
|
|
{ return std::__addressof(value); }
|
|
|
|
|
|
|
|
tracker_allocator() _GLIBCXX_USE_NOEXCEPT
|
2002-11-26 08:53:12 +08:00
|
|
|
{ }
|
|
|
|
|
2011-06-11 01:14:40 +08:00
|
|
|
tracker_allocator(const tracker_allocator&) _GLIBCXX_USE_NOEXCEPT
|
2002-11-26 08:53:12 +08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
template<class U>
|
2011-06-11 01:14:40 +08:00
|
|
|
tracker_allocator(const tracker_allocator<U>&) _GLIBCXX_USE_NOEXCEPT
|
2002-11-26 08:53:12 +08:00
|
|
|
{ }
|
|
|
|
|
2011-06-11 01:14:40 +08:00
|
|
|
~tracker_allocator() _GLIBCXX_USE_NOEXCEPT
|
2002-11-26 08:53:12 +08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
size_type
|
2011-06-11 01:14:40 +08:00
|
|
|
max_size() const _GLIBCXX_USE_NOEXCEPT
|
2006-10-04 01:01:57 +08:00
|
|
|
{ return size_type(-1) / sizeof(T); }
|
2002-11-26 08:53:12 +08:00
|
|
|
|
|
|
|
pointer
|
2003-01-14 12:56:56 +08:00
|
|
|
allocate(size_type n, const void* = 0)
|
2006-10-04 01:01:57 +08:00
|
|
|
{ return static_cast<pointer>(counter_type::allocate(n * sizeof(T))); }
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2011-06-05 01:17:57 +08:00
|
|
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
|
|
|
template<typename U, typename... Args>
|
|
|
|
void
|
|
|
|
construct(U* p, Args&&... args)
|
|
|
|
{
|
|
|
|
::new((void *)p) U(std::forward<Args>(args)...);
|
|
|
|
counter_type::construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
void
|
|
|
|
destroy(U* p)
|
|
|
|
{
|
|
|
|
p->~U();
|
|
|
|
counter_type::destroy();
|
|
|
|
}
|
|
|
|
#else
|
2002-11-26 08:53:12 +08:00
|
|
|
void
|
|
|
|
construct(pointer p, const T& value)
|
|
|
|
{
|
throw_allocator.h (throw_allocator<>:: construct<>(pointer, _Args&&...)): Add.
2007-10-26 Paolo Carlini <pcarlini@suse.de>
* include/ext/throw_allocator.h (throw_allocator<>::
construct<>(pointer, _Args&&...)): Add.
* include/ext/pool_allocator.h (__pool_alloc<>::
construct<>(pointer, _Args&&...)): Likewise.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/bitmap_allocator.h (bitmap_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/new_allocator.h (new_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/malloc_allocator.h (malloc_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/array_allocator.h (array_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/mt_allocator.h (__mt_alloc<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/util/testsuite_allocator.h (tracker_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
(uneq_allocator<>::construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/ext/mt_allocator/variadic_construct.cc: New.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/throw_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/pool_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/bitmap_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/array_allocator/variadic_construct.cc: Likewise.
From-SVN: r129672
2007-10-27 08:41:21 +08:00
|
|
|
::new ((void *)p) T(value);
|
2006-10-04 01:01:57 +08:00
|
|
|
counter_type::construct();
|
2002-11-26 08:53:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
destroy(pointer p)
|
|
|
|
{
|
|
|
|
p->~T();
|
2006-10-04 01:01:57 +08:00
|
|
|
counter_type::destroy();
|
2002-11-26 08:53:12 +08:00
|
|
|
}
|
2011-06-05 01:17:57 +08:00
|
|
|
#endif
|
2002-11-26 08:53:12 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
deallocate(pointer p, size_type num)
|
2006-10-04 01:01:57 +08:00
|
|
|
{ counter_type::deallocate(p, num * sizeof(T)); }
|
2002-11-26 08:53:12 +08:00
|
|
|
};
|
|
|
|
|
2003-01-14 12:56:56 +08:00
|
|
|
template<class T1, class T2>
|
|
|
|
bool
|
2006-10-04 01:01:57 +08:00
|
|
|
operator==(const tracker_allocator<T1>&,
|
|
|
|
const tracker_allocator<T2>&) throw()
|
2003-01-14 12:56:56 +08:00
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
template<class T1, class T2>
|
|
|
|
bool
|
2006-10-04 01:01:57 +08:00
|
|
|
operator!=(const tracker_allocator<T1>&,
|
|
|
|
const tracker_allocator<T2>&) throw()
|
2003-01-14 12:56:56 +08:00
|
|
|
{ return false; }
|
2004-07-29 00:37:20 +08:00
|
|
|
|
2004-09-02 06:17:00 +08:00
|
|
|
bool
|
|
|
|
check_construct_destroy(const char* tag, int expected_c, int expected_d);
|
2004-07-29 00:37:20 +08:00
|
|
|
|
2004-10-15 07:03:26 +08:00
|
|
|
template<typename Alloc>
|
2005-12-28 19:47:56 +08:00
|
|
|
bool
|
2004-10-15 07:03:26 +08:00
|
|
|
check_deallocate_null()
|
|
|
|
{
|
|
|
|
// Let's not core here...
|
|
|
|
Alloc a;
|
2010-06-04 03:15:56 +08:00
|
|
|
a.deallocate(0, 1);
|
|
|
|
a.deallocate(0, 10);
|
2005-12-28 19:47:56 +08:00
|
|
|
return true;
|
2004-10-15 07:03:26 +08:00
|
|
|
}
|
2004-10-21 08:06:02 +08:00
|
|
|
|
|
|
|
template<typename Alloc>
|
|
|
|
bool
|
|
|
|
check_allocate_max_size()
|
|
|
|
{
|
|
|
|
Alloc a;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
a.allocate(a.max_size() + 1);
|
|
|
|
}
|
|
|
|
catch(std::bad_alloc&)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
re PR libstdc++/25288 (std::list insert members should have no effects if an exception is thrown)
2005-12-09 Paolo Carlini <pcarlini@suse.de>
Howard Hinnant <hhinnant@apple.com>
PR libstdc++/25288
* include/bits/stl_list.h (list<>::_M_insert_dispatch, _M_fill_insert):
Remove.
(_M_initialize_dispatch, _M_fill_initialize): Add.
(list(size_type, const value_type&, const allocator_type&),
list(const list&), list(_InputIterator, _InputIterator,
const allocator_type&): Use the latter.
(insert(iterator, size_type, const value_type&), insert(iterator,
_InputIterator, _InputIterator)): Use construction & splice.
* testsuite/23_containers/list/modifiers/insert/25288.cc: New.
* testsuite/testsuite_allocator.h (class throw_allocator): Add.
* include/bits/stl_list.h (list<>::insert, erase): Fix wrong comments.
Co-Authored-By: Howard Hinnant <hhinnant@apple.com>
From-SVN: r108313
2005-12-10 02:24:53 +08:00
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
|
|
|
|
// A simple allocator which can be constructed endowed of a given
|
|
|
|
// "personality" (an integer), queried in operator== to simulate the
|
|
|
|
// behavior of realworld "unequal" allocators (i.e., not exploiting
|
|
|
|
// the provision in 20.1.5/4, first bullet). A global unordered_map,
|
|
|
|
// filled at allocation time with (pointer, personality) pairs, is
|
|
|
|
// then consulted to enforce the requirements in Table 32 about
|
|
|
|
// deallocation vs allocator equality. Note that this allocator is
|
|
|
|
// swappable, not assignable, consistently with Option 3 of DR 431
|
|
|
|
// (see N1599).
|
|
|
|
struct uneq_allocator_base
|
|
|
|
{
|
|
|
|
typedef std::tr1::unordered_map<void*, int> map_type;
|
|
|
|
|
|
|
|
// Avoid static initialization troubles and/or bad interactions
|
|
|
|
// with tests linking testsuite_allocator.o and playing globally
|
|
|
|
// with operator new/delete.
|
|
|
|
static map_type&
|
|
|
|
get_map()
|
|
|
|
{
|
|
|
|
static map_type alloc_map;
|
|
|
|
return alloc_map;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tp>
|
|
|
|
class uneq_allocator
|
|
|
|
: private uneq_allocator_base
|
|
|
|
{
|
|
|
|
public:
|
2010-06-08 09:46:10 +08:00
|
|
|
typedef std::size_t size_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
2006-01-03 21:19:23 +08:00
|
|
|
typedef Tp* pointer;
|
|
|
|
typedef const Tp* const_pointer;
|
|
|
|
typedef Tp& reference;
|
|
|
|
typedef const Tp& const_reference;
|
|
|
|
typedef Tp value_type;
|
|
|
|
|
|
|
|
template<typename Tp1>
|
|
|
|
struct rebind
|
|
|
|
{ typedef uneq_allocator<Tp1> other; };
|
|
|
|
|
2011-06-11 01:14:40 +08:00
|
|
|
uneq_allocator() _GLIBCXX_USE_NOEXCEPT
|
2006-01-03 21:19:23 +08:00
|
|
|
: personality(0) { }
|
|
|
|
|
2011-06-11 01:14:40 +08:00
|
|
|
uneq_allocator(int person) _GLIBCXX_USE_NOEXCEPT
|
2006-01-03 21:19:23 +08:00
|
|
|
: personality(person) { }
|
|
|
|
|
|
|
|
template<typename Tp1>
|
2011-06-11 01:14:40 +08:00
|
|
|
uneq_allocator(const uneq_allocator<Tp1>& b) _GLIBCXX_USE_NOEXCEPT
|
2006-01-03 21:19:23 +08:00
|
|
|
: personality(b.get_personality()) { }
|
|
|
|
|
2011-06-11 01:14:40 +08:00
|
|
|
~uneq_allocator() _GLIBCXX_USE_NOEXCEPT
|
|
|
|
{ }
|
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
int get_personality() const { return personality; }
|
|
|
|
|
|
|
|
pointer
|
2011-06-11 01:14:40 +08:00
|
|
|
address(reference x) const _GLIBCXX_NOEXCEPT
|
|
|
|
{ return std::__addressof(x); }
|
2006-01-03 21:19:23 +08:00
|
|
|
|
|
|
|
const_pointer
|
2011-06-11 01:14:40 +08:00
|
|
|
address(const_reference x) const _GLIBCXX_NOEXCEPT
|
|
|
|
{ return std::__addressof(x); }
|
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
pointer
|
|
|
|
allocate(size_type n, const void* = 0)
|
|
|
|
{
|
|
|
|
if (__builtin_expect(n > this->max_size(), false))
|
|
|
|
std::__throw_bad_alloc();
|
|
|
|
|
|
|
|
pointer p = static_cast<Tp*>(::operator new(n * sizeof(Tp)));
|
|
|
|
try
|
|
|
|
{
|
|
|
|
get_map().insert(map_type::value_type(reinterpret_cast<void*>(p),
|
|
|
|
personality));
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
::operator delete(p);
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
2011-06-11 01:14:40 +08:00
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
void
|
|
|
|
deallocate(pointer p, size_type)
|
|
|
|
{
|
2011-06-11 01:14:40 +08:00
|
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
|
|
|
|
VERIFY( p );
|
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
map_type::iterator it = get_map().find(reinterpret_cast<void*>(p));
|
2011-06-11 01:14:40 +08:00
|
|
|
VERIFY( it != get_map().end() );
|
2006-01-03 21:19:23 +08:00
|
|
|
|
|
|
|
// Enforce requirements in Table 32 about deallocation vs
|
|
|
|
// allocator equality.
|
2011-06-11 01:14:40 +08:00
|
|
|
VERIFY( it->second == personality );
|
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
get_map().erase(it);
|
|
|
|
::operator delete(p);
|
|
|
|
}
|
2011-06-11 01:14:40 +08:00
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
size_type
|
2011-06-11 01:14:40 +08:00
|
|
|
max_size() const _GLIBCXX_USE_NOEXCEPT
|
2006-10-04 01:01:57 +08:00
|
|
|
{ return size_type(-1) / sizeof(Tp); }
|
2011-06-11 01:14:40 +08:00
|
|
|
|
throw_allocator.h (throw_allocator<>:: construct<>(pointer, _Args&&...)): Add.
2007-10-26 Paolo Carlini <pcarlini@suse.de>
* include/ext/throw_allocator.h (throw_allocator<>::
construct<>(pointer, _Args&&...)): Add.
* include/ext/pool_allocator.h (__pool_alloc<>::
construct<>(pointer, _Args&&...)): Likewise.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/bitmap_allocator.h (bitmap_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/new_allocator.h (new_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/malloc_allocator.h (malloc_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/array_allocator.h (array_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/mt_allocator.h (__mt_alloc<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/util/testsuite_allocator.h (tracker_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
(uneq_allocator<>::construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/ext/mt_allocator/variadic_construct.cc: New.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/throw_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/pool_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/bitmap_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/array_allocator/variadic_construct.cc: Likewise.
From-SVN: r129672
2007-10-27 08:41:21 +08:00
|
|
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
2011-06-05 01:17:57 +08:00
|
|
|
template<typename U, typename... Args>
|
throw_allocator.h (throw_allocator<>:: construct<>(pointer, _Args&&...)): Add.
2007-10-26 Paolo Carlini <pcarlini@suse.de>
* include/ext/throw_allocator.h (throw_allocator<>::
construct<>(pointer, _Args&&...)): Add.
* include/ext/pool_allocator.h (__pool_alloc<>::
construct<>(pointer, _Args&&...)): Likewise.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/bitmap_allocator.h (bitmap_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/new_allocator.h (new_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/malloc_allocator.h (malloc_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/array_allocator.h (array_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/mt_allocator.h (__mt_alloc<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/util/testsuite_allocator.h (tracker_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
(uneq_allocator<>::construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/ext/mt_allocator/variadic_construct.cc: New.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/throw_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/pool_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/bitmap_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/array_allocator/variadic_construct.cc: Likewise.
From-SVN: r129672
2007-10-27 08:41:21 +08:00
|
|
|
void
|
2011-06-05 01:17:57 +08:00
|
|
|
construct(U* p, Args&&... args)
|
|
|
|
{ ::new((void *)p) U(std::forward<Args>(args)...); }
|
throw_allocator.h (throw_allocator<>:: construct<>(pointer, _Args&&...)): Add.
2007-10-26 Paolo Carlini <pcarlini@suse.de>
* include/ext/throw_allocator.h (throw_allocator<>::
construct<>(pointer, _Args&&...)): Add.
* include/ext/pool_allocator.h (__pool_alloc<>::
construct<>(pointer, _Args&&...)): Likewise.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/bitmap_allocator.h (bitmap_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/new_allocator.h (new_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/malloc_allocator.h (malloc_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/array_allocator.h (array_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* include/ext/mt_allocator.h (__mt_alloc<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/util/testsuite_allocator.h (tracker_allocator<>::
construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
(uneq_allocator<>::construct<>(pointer, _Args&&...)): Add.
(construct(pointer, const _Tp&)): Cast pointer to void*.
* testsuite/ext/mt_allocator/variadic_construct.cc: New.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/throw_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/pool_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/bitmap_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/array_allocator/variadic_construct.cc: Likewise.
From-SVN: r129672
2007-10-27 08:41:21 +08:00
|
|
|
|
2011-06-05 01:17:57 +08:00
|
|
|
template<typename U>
|
|
|
|
void
|
|
|
|
destroy(U* p) { p->~U(); }
|
2006-01-03 21:19:23 +08:00
|
|
|
|
2011-05-20 01:20:22 +08:00
|
|
|
// Not copy assignable...
|
|
|
|
uneq_allocator&
|
|
|
|
operator=(const uneq_allocator&) = delete;
|
2011-06-05 01:17:57 +08:00
|
|
|
#else
|
|
|
|
void
|
|
|
|
construct(pointer p, const Tp& val)
|
|
|
|
{ ::new((void *)p) Tp(val); }
|
2011-05-20 01:20:22 +08:00
|
|
|
|
2011-06-05 01:17:57 +08:00
|
|
|
void
|
|
|
|
destroy(pointer p) { p->~Tp(); }
|
2011-05-20 01:20:22 +08:00
|
|
|
|
2011-06-05 01:17:57 +08:00
|
|
|
private:
|
2006-01-03 21:19:23 +08:00
|
|
|
// Not assignable...
|
|
|
|
uneq_allocator&
|
|
|
|
operator=(const uneq_allocator&);
|
2011-05-20 01:20:22 +08:00
|
|
|
#endif
|
2006-01-03 21:19:23 +08:00
|
|
|
|
2011-06-05 01:17:57 +08:00
|
|
|
private:
|
|
|
|
|
2006-01-03 21:19:23 +08:00
|
|
|
// ... yet swappable!
|
|
|
|
friend inline void
|
|
|
|
swap(uneq_allocator& a, uneq_allocator& b)
|
|
|
|
{ std::swap(a.personality, b.personality); }
|
|
|
|
|
|
|
|
template<typename Tp1>
|
|
|
|
friend inline bool
|
|
|
|
operator==(const uneq_allocator& a, const uneq_allocator<Tp1>& b)
|
|
|
|
{ return a.personality == b.personality; }
|
|
|
|
|
|
|
|
template<typename Tp1>
|
|
|
|
friend inline bool
|
|
|
|
operator!=(const uneq_allocator& a, const uneq_allocator<Tp1>& b)
|
|
|
|
{ return !(a == b); }
|
|
|
|
|
|
|
|
int personality;
|
|
|
|
};
|
2011-07-09 21:06:29 +08:00
|
|
|
|
|
|
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
|
|
|
// An uneq_allocator which can be used to test allocator propagation.
|
|
|
|
template<typename Tp, bool Propagate>
|
|
|
|
class propagating_allocator : public uneq_allocator<Tp>
|
|
|
|
{
|
|
|
|
typedef uneq_allocator<Tp> base_alloc;
|
|
|
|
base_alloc& base() { return *this; }
|
|
|
|
const base_alloc& base() const { return *this; }
|
|
|
|
void swap_base(base_alloc& b) { swap(b, this->base()); }
|
|
|
|
|
|
|
|
typedef std::integral_constant<bool, Propagate> trait_type;
|
|
|
|
|
|
|
|
public:
|
|
|
|
template<typename Up>
|
|
|
|
struct rebind { typedef propagating_allocator<Up, Propagate> other; };
|
|
|
|
|
|
|
|
propagating_allocator(int i) noexcept
|
|
|
|
: base_alloc(i)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
propagating_allocator(const propagating_allocator<Up, Propagate>& a)
|
|
|
|
noexcept
|
|
|
|
: base_alloc(a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
propagating_allocator() noexcept = default;
|
|
|
|
|
|
|
|
propagating_allocator(const propagating_allocator&) noexcept = default;
|
|
|
|
|
|
|
|
template<bool P2>
|
|
|
|
propagating_allocator&
|
|
|
|
operator=(const propagating_allocator<Tp, P2>& a) noexcept
|
|
|
|
{
|
|
|
|
static_assert(P2, "assigning propagating_allocator<T, true>");
|
|
|
|
propagating_allocator(a).swap_base(*this);
|
2011-07-12 01:19:53 +08:00
|
|
|
return *this;
|
2011-07-09 21:06:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// postcondition: a.get_personality() == 0
|
|
|
|
propagating_allocator(propagating_allocator&& a) noexcept
|
|
|
|
: base_alloc()
|
|
|
|
{ swap_base(a); }
|
|
|
|
|
|
|
|
// postcondition: a.get_personality() == 0
|
|
|
|
propagating_allocator&
|
|
|
|
operator=(propagating_allocator&& a) noexcept
|
|
|
|
{
|
|
|
|
propagating_allocator(std::move(a)).swap_base(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef trait_type propagate_on_container_copy_assignment;
|
|
|
|
typedef trait_type propagate_on_container_move_assignment;
|
|
|
|
typedef trait_type propagate_on_container_swap;
|
|
|
|
|
|
|
|
propagating_allocator select_on_container_copy_construction() const
|
|
|
|
{ return Propagate ? *this : propagating_allocator(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
re PR libstdc++/50118 (node-based containers cannot use allocators with explicit constructor template)
2011-08-29 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/50118
* include/bits/stl_list.h (_List_base<>::
_List_base(const allocator_type&)): Remove.
(_List_base<>::_List_base(const _Node_alloc_type&)): Add.
(list<>:list(const allocator_type&), list(size_type, const
value_type&, const allocator_type&),
list(initializer_list<, const allocator_type&),
list(_InputIterator, _InputIterator, const allocator_type&),
insert(iterator, size_type, const value_type&),
insert(iterator, _InputIterator, _InputIterator)): Adjust.
* include/bits/stl_tree.h (_Rb_tree<>::_Rb_tree(const _Compare&,
const allocator_type&)): Fix.
* include/bits/stl_map.h (map<>::map(const _Compare&,
const allocator_type&), map(initializer_list<>,
const _Compare&, const allocator_type&), map(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Adjust.
* include/bits/stl_set.h (set<>::set(const _Compare&,
const allocator_type&), set(initializer_list<>,
const _Compare&, const allocator_type&), set(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Likewise.
* include/bits/stl_multimap.h (multimap<>::multimap(const _Compare&,
const allocator_type&), multimap(initializer_list<>,
const _Compare&, const allocator_type&), multimap(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Likewise.
* include/bits/stl_multiset.h (multiset<>::multiset(const _Compare&,
const allocator_type&), multiset(initializer_list<>,
const _Compare&, const allocator_type&), multiset(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Likewise.
* include/bits/forward_list.h (_Fwd_list_base<>::
_Fwd_list_base(const _Alloc&), _Fwd_list_base(const _Fwd_list_base&,
const _Alloc&), _Fwd_list_base(_Fwd_list_base&&, const _Alloc&)):
Remove.
(_Fwd_list_base<>::_Fwd_list_base(const _Node_alloc_type&),
_Fwd_list_base(const _Fwd_list_base&,
const _Node_alloc_type&), _Fwd_list_base(_Fwd_list_base&&,
const _Node_alloc_type&)): Add.
(forward_list<>::forward_list(const _Alloc&),
forward_list(const forward_list&, const _Alloc&),
forward_list(forward_list&&, const _Alloc&),
forward_list(size_type, const _Tp&, const _Alloc&),
forward_list(_InputIterator, _InputIterator, const _Alloc&),
forward_list(std::initializer_list<>, const _Alloc&),
get_allocator): Adjust.
* include/bits/forward_list.tcc
* testsuite/util/testsuite_allocator.h (ExplicitConsAlloc): Add.
* testsuite/23_containers/unordered_map/requirements/
explicit_instantiation/5.cc: New.
* testsuite/23_containers/multimap/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/multimap/requirements/
explicit_instantiation/5_c++0x.cc: Likewise.
* testsuite/23_containers/set/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/set/requirements/explicit_instantiation/
5_c++0x.cc: Likewise.
* testsuite/23_containers/unordered_multimap/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/unordered_set/requirements/
explicit_instantiation/5.cc: Likewise.
testsuite/23_containers/multiset/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/multiset/requirements/
explicit_instantiation/5_c++0x.cc: Likewise.
* testsuite/23_containers/list/requirements/explicit_instantiation/
5_c++0x.cc: Likewise.
* testsuite/23_containers/list/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/unordered_multiset/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/map/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/map/requirements/explicit_instantiation/
5_c++0x.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Adjust dg-error line number.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Likewise.
From-SVN: r178230
2011-08-29 21:40:33 +08:00
|
|
|
template<typename Tp>
|
|
|
|
struct ExplicitConsAlloc : std::allocator<Tp>
|
|
|
|
{
|
|
|
|
ExplicitConsAlloc() { }
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
explicit
|
|
|
|
ExplicitConsAlloc(const ExplicitConsAlloc<Up>&) { }
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
struct rebind
|
|
|
|
{ typedef ExplicitConsAlloc<Up> other; };
|
|
|
|
};
|
|
|
|
|
2007-12-10 03:43:49 +08:00
|
|
|
} // namespace __gnu_test
|
2002-11-26 08:53:12 +08:00
|
|
|
|
2003-07-05 12:05:45 +08:00
|
|
|
#endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H
|