From patchwork Sun Jun 16 17:16:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 251727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 7E36D2C00B1 for ; Mon, 17 Jun 2013 03:16:50 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=RQsqrGJdp8ptpZd64fTWy0sGMimqhrwn6dJgXW/mVO7aFN Iro3yRzpnIYC6Wc61XCSFDRGnEzekVqSu/S0M4FKQ0KZAJ3Gek5cpjQKrs3WNhll hbjzW4teFRYwSV8yEaGRjm7/Xd4HuG4Sb3MEqBWTHn5Mx4hEMWY4v4f7NBl44= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=M7lMukV58yOUKCXpyd3iGJQakDY=; b=Zov58JRQdJOJjYoU3DDB gvC95VQ3/91JGsy6kXqTt387O22uzRZoQc8ekCnKeG7w+UVnhyISixYo6S+Uw13N uC/cFsUW1N6uFzLUE7ms+dCTSH+mxGZRITSOdhcwd/M96K9Lwh5n3d9XZkRgrkK5 0sG72oUh4UsSNzDDHiQeIcE= Received: (qmail 31661 invoked by alias); 16 Jun 2013 17:16:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31635 invoked by uid 89); 16 Jun 2013 17:16:35 -0000 X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, SPF_PASS autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mail-lb0-f174.google.com (HELO mail-lb0-f174.google.com) (209.85.217.174) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 16 Jun 2013 17:16:33 +0000 Received: by mail-lb0-f174.google.com with SMTP id x10so1863300lbi.33 for ; Sun, 16 Jun 2013 10:16:30 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.78.73 with SMTP id z9mr4838504lbw.14.1371402990738; Sun, 16 Jun 2013 10:16:30 -0700 (PDT) Received: by 10.112.160.104 with HTTP; Sun, 16 Jun 2013 10:16:30 -0700 (PDT) Date: Sun, 16 Jun 2013 18:16:30 +0100 Message-ID: Subject: [patch] fix libstdc++/57263 From: Jonathan Wakely To: "libstdc++" , gcc-patches X-Virus-Found: No PR libstdc++/57263 * include/bits/forward_list.h (_Fwd_list_base): Convert to/from allocator's pointer type. * include/bits/hashtable.h (_Hashtable): Likewise. * testsuite/util/testsuite_allocator.h (CustomPointerAlloc): Add. * testsuite/23_containers/forward_list/allocator/ext_ptr.cc: New. * testsuite/23_containers/unordered_set/allocator/ext_ptr.cc: New. * testsuite/23_containers/vector/allocator/ext_ptr.cc: New. Tested x86_64-linux, committed to trunk. commit b4514c0c6f530fbbcc66a478b5ef45263907f1d3 Author: Jonathan Wakely Date: Wed May 15 01:10:22 2013 +0100 PR libstdc++/57263 * include/bits/forward_list.h (_Fwd_list_base): Convert to/from allocator's pointer type. * include/bits/hashtable.h (_Hashtable): Likewise. * testsuite/util/testsuite_allocator.h (CustomPointerAlloc): Add. * testsuite/23_containers/forward_list/allocator/ext_ptr.cc: New. * testsuite/23_containers/unordered_set/allocator/ext_ptr.cc: New. * testsuite/23_containers/vector/allocator/ext_ptr.cc: New. diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index e7c4bdd..c3cee97 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -338,7 +338,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Node* _M_get_node() - { return _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1); } + { + auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1); + return std::__addressof(*__ptr); + } template _Node* @@ -367,7 +370,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER void _M_put_node(_Node* __p) - { _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __p, 1); } + { + typedef typename _Node_alloc_traits::pointer _Ptr; + auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__p); + _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1); + } _Fwd_list_node_base* _M_erase_after(_Fwd_list_node_base* __pos); diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 0ff6e13..8ce264e 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -775,7 +775,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _H1, _H2, _Hash, _RehashPolicy, _Traits>:: _M_allocate_node(_Args&&... __args) { - __node_type* __n = _Node_alloc_traits::allocate(_M_node_allocator(), 1); + auto __nptr = _Node_alloc_traits::allocate(_M_node_allocator(), 1); + __node_type* __n = std::__addressof(*__nptr); __try { _Value_alloc_type __a(_M_node_allocator()); @@ -786,7 +787,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } __catch(...) { - _Node_alloc_traits::deallocate(_M_node_allocator(), __n, 1); + _Node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1); __throw_exception_again; } } @@ -800,10 +801,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _H1, _H2, _Hash, _RehashPolicy, _Traits>:: _M_deallocate_node(__node_type* __n) { + typedef typename _Node_alloc_traits::pointer _Ptr; + auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__n); _Value_alloc_type __a(_M_node_allocator()); _Value_alloc_traits::destroy(__a, __n->_M_valptr()); __n->~__node_type(); - _Node_alloc_traits::deallocate(_M_node_allocator(), __n, 1); + _Node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1); } template:: _M_deallocate_buckets(__bucket_type* __bkts, size_type __n) { + typedef typename _Bucket_alloc_traits::pointer _Ptr; + auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__bkts); _Bucket_alloc_type __alloc(_M_node_allocator()); - _Bucket_alloc_traits::deallocate(__alloc, __bkts, __n); + _Bucket_alloc_traits::deallocate(__alloc, __ptr, __n); } template. + +// { dg-options "-std=gnu++11" } + +#include +#include +#include +#include + +struct T { int i; }; +bool operator==(const T& l, const T& r) { return l.i == r.i; } +bool operator<(const T& l, const T& r) { return l.i < r.i; } + +using __gnu_test::CustomPointerAlloc; + +template class std::forward_list>; + +void test01() +{ + bool test __attribute__((unused)) = true; + typedef CustomPointerAlloc alloc_type; + typedef std::forward_list test_type; + test_type v; + v.push_front(T()); + VERIFY( ++v.begin() == v.end() ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/ext_ptr.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/ext_ptr.cc new file mode 100644 index 0000000..55d9af3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/ext_ptr.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2013 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 +#include +#include + +struct T { int i; }; +bool operator==(const T& l, const T& r) { return l.i == r.i; } +struct H { std::size_t operator()(const T& t) const noexcept { return t.i; } +}; +struct E : std::equal_to { }; + +using __gnu_test::CustomPointerAlloc; + +template class std::unordered_set>; + +void test01() +{ + bool test __attribute__((unused)) = true; + typedef CustomPointerAlloc alloc_type; + typedef std::unordered_set test_type; + test_type v; + v.insert(T()); + VERIFY( ++v.begin() == v.end() ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/ext_ptr.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/ext_ptr.cc new file mode 100644 index 0000000..b94a47a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/ext_ptr.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2013 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 +#include +#include + +struct T { int i; }; + +using __gnu_test::CustomPointerAlloc; + +template class std::vector>; + +void test01() +{ + bool test __attribute__((unused)) = true; + typedef CustomPointerAlloc alloc_type; + typedef std::vector test_type; + test_type v; + v.push_back(T()); + VERIFY( ++v.begin() == v.end() ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h index 2360274..d569eb0 100644 --- a/libstdc++-v3/testsuite/util/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h @@ -28,6 +28,7 @@ #include #include +#include #include namespace __gnu_test @@ -488,6 +489,36 @@ namespace __gnu_test { typedef ExplicitConsAlloc other; }; }; +#if __cplusplus >= 201103L + template + class CustomPointerAlloc : public std::allocator + { + template> + using Ptr = __gnu_cxx::_Pointer_adapter; + + public: + CustomPointerAlloc() = default; + + template + CustomPointerAlloc(const CustomPointerAlloc&) { } + + template + struct rebind + { typedef CustomPointerAlloc other; }; + + typedef Ptr pointer; + typedef Ptr const_pointer; + typedef Ptr void_pointer; + typedef Ptr const_void_pointer; + + pointer allocate(std::size_t n, pointer = {}) + { return pointer(std::allocator::allocate(n)); } + + void deallocate(pointer p, std::size_t n) + { std::allocator::deallocate(std::addressof(*p), n); } + }; +#endif + } // namespace __gnu_test #endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H