From patchwork Wed Jan 16 09:25:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 212461 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]) by ozlabs.org (Postfix) with SMTP id C8E7B2C0091 for ; Wed, 16 Jan 2013 20:25:45 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1358933147; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=Ugl/LkX SZZye73v/4ebVwlC0AKs=; b=gmhvTDpVCp5gDvN31p9bCXteULjal922LACgu1f 8oRmG7LYNkVVWVl9W74HrBL7lm/di00eiM9wZzNcP7tNvNgksTZmg+JvjmUmO5Dm rzNwR5pGOaBgRhxIMYoJUvVrsHDcmwuOpaI0WNVJwmU8xIaJpkksWoQRJeurlIhT J5Vg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:X-Received:Received:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=eDyVDL6uQ/+jktTHW81SrTcKIXv1sf4/Trypejwzq/Y/7akjt1t78BivHbOwWf ENJ/6mxi3VT+1RpUl9xx3hH5x5vAwV4XkOYyKCyX0cTGgOlWw4/2cW9RE6KuLT2U KR7ebumYpjian0VQxfbO+X0jpXcqmoPyTdPZ725jjJ5MQ=; Received: (qmail 21260 invoked by alias); 16 Jan 2013 09:25:27 -0000 Received: (qmail 21237 invoked by uid 22791); 16 Jan 2013 09:25:25 -0000 X-SWARE-Spam-Status: No, hits=-4.5 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-la0-f50.google.com (HELO mail-la0-f50.google.com) (209.85.215.50) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Jan 2013 09:25:17 +0000 Received: by mail-la0-f50.google.com with SMTP id fs13so1140484lab.9 for ; Wed, 16 Jan 2013 01:25:15 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.152.144.38 with SMTP id sj6mr377156lab.48.1358328315052; Wed, 16 Jan 2013 01:25:15 -0800 (PST) Received: by 10.112.125.71 with HTTP; Wed, 16 Jan 2013 01:25:14 -0800 (PST) Date: Wed, 16 Jan 2013 09:25:14 +0000 Message-ID: Subject: [patch] Fix libstdc++/55043 - issue with nesting unordered_map containing unique_ptr into vector From: Jonathan Wakely To: "libstdc++" , gcc-patches 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 This fixes a regression caused by supporting the C++11 allocator requirements in std::vector, and the fact that the unordered containers don't have noexcept move constructors. Fixed by specializing is_copy_constructible for the unordered containers so vector doesn't try to copy them when their element type is not CopyInsertable into the container, and instead resorts to a move that might throw. PR libstdc++/55043 * include/std/unordered_map: Include alloc_traits.h * include/std/unordered_set: Likewise. * include/bits/alloc_traits.h: Define __is_copy_insertable. * include/bits/unordered_map.h: Use it. * include/bits/unordered_set.h: Likewise. * include/debug/unordered_map.h: Likewise. * include/debug/unordered_set.h: Likewise. * include/profile/unordered_map.h: Likewise. * include/profile/unordered_set.h: Likewise. * include/bits/hashtable.h: Fix comment typos. * testsuite/23_containers/unordered_map/55043.cc: New. * testsuite/23_containers/unordered_multimap/55043.cc: New. * testsuite/23_containers/unordered_multiset/55043.cc: New. * testsuite/23_containers/unordered_set/55043.cc: New. Tested x86_64-linux, in normal, debug and profile modes. Committed to trunk, to be committed to the 4.7 branch shortly. commit e9c94b31c67f26e52c9927a4eedb39095efcd8be Author: Jonathan Wakely Date: Wed Jan 16 09:19:11 2013 +0000 PR libstdc++/55043 * include/std/unordered_map: Include alloc_traits.h * include/std/unordered_set: Likewise. * include/bits/alloc_traits.h: Define __is_copy_insertable. * include/bits/unordered_map.h: Use it. * include/bits/unordered_set.h: Likewise. * include/debug/unordered_map.h: Likewise. * include/debug/unordered_set.h: Likewise. * include/profile/unordered_map.h: Likewise. * include/profile/unordered_set.h: Likewise. * include/bits/hashtable.h: Fix comment typos. * testsuite/23_containers/unordered_map/55043.cc: New. * testsuite/23_containers/unordered_multimap/55043.cc: New. * testsuite/23_containers/unordered_multiset/55043.cc: New. * testsuite/23_containers/unordered_set/55043.cc: New. diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index 9abadbb..c6259a1 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -1,6 +1,6 @@ // Allocator traits -*- C++ -*- -// Copyright (C) 2011-2012 Free Software Foundation, Inc. +// Copyright (C) 2011-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 @@ -39,6 +39,9 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION + template + class allocator; + template class __alloctr_rebind_helper { @@ -506,6 +509,41 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, __do_alloc_on_swap(__one, __two, __pocs()); } + template + class __is_copy_insertable_impl + { + typedef allocator_traits<_Alloc> _Traits; + + template(), + std::declval<_Up*>(), + std::declval()))> + static true_type + _M_select(int); + + template + static false_type + _M_select(...); + + public: + typedef decltype(_M_select(0)) type; + }; + + template + struct __is_copy_insertable + : __is_copy_insertable_impl<_Alloc>::type + { }; + + // std::allocator<_Tp> just requires CopyConstructible + template + struct __is_copy_insertable> + : is_copy_constructible<_Tp> + { }; + + template + using __has_copy_insertable_val + = __is_copy_insertable; + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index fab6c7c..49cb4db 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -370,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Hashtable(_Hashtable&&); - // Use delegating construtors. + // Use delegating constructors. explicit _Hashtable(size_type __n = 10, const _H1& __hf = _H1(), @@ -914,7 +914,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_element_count(__ht._M_element_count), _M_rehash_policy(__ht._M_rehash_policy) { - // Update, if necessary, bucket pointing to before begin that hasn't move. + // Update, if necessary, bucket pointing to before begin that hasn't moved. if (_M_begin()) _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin(); __ht._M_rehash_policy = _RehashPolicy(); diff --git a/libstdc++-v3/include/bits/unordered_map.h b/libstdc++-v3/include/bits/unordered_map.h index 9fa0553..0235a99 100644 --- a/libstdc++-v3/include/bits/unordered_map.h +++ b/libstdc++-v3/include/bits/unordered_map.h @@ -1408,6 +1408,26 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return !(__x == __y); } _GLIBCXX_END_NAMESPACE_CONTAINER + + template + struct + is_copy_constructible<_GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, + _Pred, _Alloc>> + : __has_copy_insertable_val<_GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, + _Pred, _Alloc>> + { }; + + template + struct + is_copy_constructible<_GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash, + _Pred, _Alloc>> + : __has_copy_insertable_val<_GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, + _Hash, _Pred, + _Alloc>> + { }; + } // namespace std #endif /* _UNORDERED_MAP_H */ diff --git a/libstdc++-v3/include/bits/unordered_set.h b/libstdc++-v3/include/bits/unordered_set.h index c3eaa48..2ada63d 100644 --- a/libstdc++-v3/include/bits/unordered_set.h +++ b/libstdc++-v3/include/bits/unordered_set.h @@ -1,6 +1,6 @@ // unordered_set implementation -*- C++ -*- -// Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2010-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 @@ -1291,6 +1291,23 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return !(__x == __y); } _GLIBCXX_END_NAMESPACE_CONTAINER + + template + struct is_copy_constructible<_GLIBCXX_STD_C::unordered_set<_Key, _Hash, + _Pred, _Alloc>> + : __has_copy_insertable_val<_GLIBCXX_STD_C::unordered_set<_Key, _Hash, + _Pred, _Alloc>> + { }; + + template + struct + is_copy_constructible<_GLIBCXX_STD_C::unordered_multiset<_Key, _Hash, + _Pred, _Alloc>> + : __has_copy_insertable_val<_GLIBCXX_STD_C::unordered_multiset<_Key, _Hash, + _Pred, + _Alloc>> + { }; + } // namespace std #endif /* _UNORDERED_SET_H */ diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map index 1c99ac8..115abb5 100644 --- a/libstdc++-v3/include/debug/unordered_map +++ b/libstdc++-v3/include/debug/unordered_map @@ -1,7 +1,6 @@ // Debugging unordered_map/unordered_multimap implementation -*- C++ -*- -// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 -// Free Software Foundation, Inc. +// Copyright (C) 2003-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 @@ -939,6 +938,30 @@ namespace __debug { return !(__x == __y); } } // namespace __debug + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template + struct + is_copy_constructible<__debug::unordered_map<_Key, _Tp, _Hash, _Pred, + _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_C::unordered_map<_Key, _Tp, + _Hash, _Pred, + _Alloc> > + { }; + + template + struct + is_copy_constructible<__debug::unordered_multimap<_Key, _Tp, _Hash, _Pred, + _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, + _Hash, _Pred, + _Alloc> > + { }; + +_GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/debug/unordered_set b/libstdc++-v3/include/debug/unordered_set index d270ecc..895c943 100644 --- a/libstdc++-v3/include/debug/unordered_set +++ b/libstdc++-v3/include/debug/unordered_set @@ -1,7 +1,6 @@ // Debugging unordered_set/unordered_multiset implementation -*- C++ -*- -// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 -// Free Software Foundation, Inc. +// Copyright (C) 2003-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 @@ -921,6 +920,27 @@ namespace __debug { return !(__x == __y); } } // namespace __debug + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template + struct + is_copy_constructible<__debug::unordered_set<_Key, _Hash, _Pred, _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_C::unordered_set<_Key, + _Hash, _Pred, + _Alloc> > + { }; + + template + struct + is_copy_constructible<__debug::unordered_multiset<_Key, _Hash, _Pred, + _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_C::unordered_multiset<_Key, + _Hash, _Pred, + _Alloc> > + { }; + +_GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/profile/unordered_map b/libstdc++-v3/include/profile/unordered_map index e7b4c37..5ebcbf6 100644 --- a/libstdc++-v3/include/profile/unordered_map +++ b/libstdc++-v3/include/profile/unordered_map @@ -1,6 +1,6 @@ // Profiling unordered_map/unordered_multimap implementation -*- C++ -*- -// Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2009-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 @@ -339,11 +339,25 @@ namespace __profile const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { return !(__x == __y); } +} // namespace __profile + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + struct + is_copy_constructible<__profile::unordered_map<_Key, _Tp, _Hash, + _Pred, _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_BASE > + { }; +_GLIBCXX_END_NAMESPACE_VERSION + #undef _GLIBCXX_BASE #undef _GLIBCXX_STD_BASE #define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> #define _GLIBCXX_STD_BASE _GLIBCXX_STD_C::_GLIBCXX_BASE +namespace __profile +{ /// Class std::unordered_multimap wrapper with performance instrumentation. template, @@ -609,6 +623,18 @@ namespace __profile { return !(__x == __y); } } // namespace __profile + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template + struct + is_copy_constructible<__profile::unordered_multimap<_Key, _Tp, _Hash, + _Pred, _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_BASE > + { }; + +_GLIBCXX_END_NAMESPACE_VERSION } // namespace std #undef _GLIBCXX_BASE diff --git a/libstdc++-v3/include/profile/unordered_set b/libstdc++-v3/include/profile/unordered_set index 357c073..ebe1c7d 100644 --- a/libstdc++-v3/include/profile/unordered_set +++ b/libstdc++-v3/include/profile/unordered_set @@ -1,6 +1,6 @@ // Profiling unordered_set/unordered_multiset implementation -*- C++ -*- -// Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2009-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 @@ -305,11 +305,23 @@ namespace __profile const unordered_set<_Key, _Hash, _Pred, _Alloc>& __y) { return !(__x == __y); } +} // namespace __profile + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + struct + is_copy_constructible<__profile::unordered_set<_Key, _Hash, _Pred, _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_BASE > + { }; +_GLIBCXX_END_NAMESPACE_VERSION + #undef _GLIBCXX_BASE #undef _GLIBCXX_STD_BASE #define _GLIBCXX_STD_BASE _GLIBCXX_STD_C::_GLIBCXX_BASE #define _GLIBCXX_BASE unordered_multiset<_Value, _Hash, _Pred, _Alloc> +namespace __profile +{ /** @brief Unordered_multiset wrapper with performance instrumentation. */ template, @@ -568,6 +580,17 @@ namespace __profile { return !(__x == __y); } } // namespace __profile + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template + struct + is_copy_constructible<__profile::unordered_multiset<_Value, _Hash, + _Pred, _Alloc>> + : is_copy_constructible< _GLIBCXX_STD_BASE > + { }; + +_GLIBCXX_END_NAMESPACE_VERSION } // namespace std #undef _GLIBCXX_BASE diff --git a/libstdc++-v3/include/std/unordered_map b/libstdc++-v3/include/std/unordered_map index 3514203..7c10173 100644 --- a/libstdc++-v3/include/std/unordered_map +++ b/libstdc++-v3/include/std/unordered_map @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc. +// Copyright (C) 2007-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 @@ -41,6 +41,7 @@ #include #include #include +#include #include // equal_to, _Identity, _Select1st #include #include diff --git a/libstdc++-v3/include/std/unordered_set b/libstdc++-v3/include/std/unordered_set index af6f624..cfe91ad 100644 --- a/libstdc++-v3/include/std/unordered_set +++ b/libstdc++-v3/include/std/unordered_set @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc. +// Copyright (C) 2007-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 @@ -41,6 +41,7 @@ #include #include #include +#include #include // equal_to, _Identity, _Select1st #include #include diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/55043.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/55043.cc new file mode 100644 index 0000000..10d36a0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/55043.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 +// . + +// libstdc++/55043 + +#include +#include + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; +}; + +using hash = std::hash; +using equal = std::equal_to; + +template + using test_type = std::unordered_map; + +void test01() +{ + typedef test_type> uim; + std::vector v; + v.emplace_back(uim()); +} + +// Unordered containers don't use allocator_traits yet so need full +// Allocator interface, derive from std::allocator to get it. +template +struct Alloc : std::allocator +{ + template + struct rebind { typedef Alloc other; }; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + typedef typename std::conditional::type arg_type; + + void construct(T* p, arg_type) const + { new((void*)p) T(); } +}; + +// verify is_copy_constructible depends on allocator +typedef test_type> uim_rval; +static_assert(std::is_copy_constructible::value, "is not copyable"); + +typedef test_type> uim_lval; +static_assert(std::is_copy_constructible::value, "is copyable"); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/55043.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/55043.cc new file mode 100644 index 0000000..9ae912ef6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/55043.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 +// . + +// libstdc++/55043 + +#include +#include + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; +}; + +using hash = std::hash; +using equal = std::equal_to; + +template + using test_type = std::unordered_multimap; + +void test01() +{ + typedef test_type> uim; + std::vector v; + v.emplace_back(uim()); +} + +// Unordered containers don't use allocator_traits yet so need full +// Allocator interface, derive from std::allocator to get it. +template +struct Alloc : std::allocator +{ + template + struct rebind { typedef Alloc other; }; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + typedef typename std::conditional::type arg_type; + + void construct(T* p, arg_type) const + { new((void*)p) T(); } +}; + +// verify is_copy_constructible depends on allocator +typedef test_type> uim_rval; +static_assert(std::is_copy_constructible::value, "is not copyable"); + +typedef test_type> uim_lval; +static_assert(std::is_copy_constructible::value, "is copyable"); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/55043.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/55043.cc new file mode 100644 index 0000000..ebb8cb8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/55043.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 +// . + +// libstdc++/55043 + +#include +#include + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; +}; + +struct equal { + bool operator()(const MoveOnly&, const MoveOnly) const { return true; } +}; +struct hash { + size_t operator()(const MoveOnly&) const { return 0; } +}; + +template + using test_type = std::unordered_multiset; + +void test01() +{ + typedef test_type> uim; + std::vector v; + v.emplace_back(uim()); +} + +// Unordered containers don't use allocator_traits yet so need full +// Allocator interface, derive from std::allocator to get it. +template +struct Alloc : std::allocator +{ + template + struct rebind { typedef Alloc other; }; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + typedef typename std::conditional::type arg_type; + + void construct(T* p, arg_type) const + { new((void*)p) T(); } +}; + +// verify is_copy_constructible depends on allocator +typedef test_type> uim_rval; +static_assert(std::is_copy_constructible::value, "is not copyable"); + +typedef test_type> uim_lval; +static_assert(std::is_copy_constructible::value, "is copyable"); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/55043.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/55043.cc new file mode 100644 index 0000000..3b0b973 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/55043.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 +// . + +// libstdc++/55043 + +#include +#include + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; +}; + +struct equal { + bool operator()(const MoveOnly&, const MoveOnly) const { return true; } +}; +struct hash { + size_t operator()(const MoveOnly&) const { return 0; } +}; + +template + using test_type = std::unordered_set; + +void test01() +{ + typedef test_type> uim; + std::vector v; + v.emplace_back(uim()); +} + +// Unordered containers don't use allocator_traits yet so need full +// Allocator interface, derive from std::allocator to get it. +template +struct Alloc : std::allocator +{ + template + struct rebind { typedef Alloc other; }; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + typedef typename std::conditional::type arg_type; + + void construct(T* p, arg_type) const + { new((void*)p) T(); } +}; + +// verify is_copy_constructible depends on allocator +typedef test_type> uim_rval; +static_assert(std::is_copy_constructible::value, "is not copyable"); + +typedef test_type> uim_lval; +static_assert(std::is_copy_constructible::value, "is copyable");