From cd4409290ea224b9ef4ebb73e23fd103494ec251 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 20 Oct 2016 12:17:55 +0100 Subject: [PATCH] PR78052 Define std::allocator::{construct,destroy} PR libstdc++/78052 * include/bits/allocator.h (allocator::construct) (allocator::destroy): Define. * testsuite/20_util/allocator/void.cc: New test. From-SVN: r241370 --- libstdc++-v3/ChangeLog | 7 ++++ libstdc++-v3/include/bits/allocator.h | 9 +++++ .../testsuite/20_util/allocator/void.cc | 40 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/allocator/void.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6f4813b9a616..5e7c3116ff9b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2016-10-20 Jonathan Wakely + + PR libstdc++/78052 + * include/bits/allocator.h (allocator::construct) + (allocator::destroy): Define. + * testsuite/20_util/allocator/void.cc: New test. + 2016-10-19 Jonathan Wakely PR libstdc++/77990 diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 605731533d0b..03953b46dbbb 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -77,6 +77,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2103. std::allocator propagate_on_container_move_assignment typedef true_type propagate_on_container_move_assignment; + + template + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template + void + destroy(_Up* __p) { __p->~_Up(); } #endif }; diff --git a/libstdc++-v3/testsuite/20_util/allocator/void.cc b/libstdc++-v3/testsuite/20_util/allocator/void.cc new file mode 100644 index 000000000000..34f3beb1345a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/void.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++11" } + +#include +#include + +template class std::allocator; + +void +test01() +{ + int i; + using alloc_type = std::allocator; + alloc_type a; + std::allocator_traits::construct(a, &i, 42); + VERIFY( i == 42 ); + std::allocator_traits::destroy(a, &i); +} + +int +main() +{ + test01(); +} -- 2.47.2