public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10838] libstdc++: Backport tests for associative container move constructors Date: Wed, 15 Jun 2022 08:14:44 +0000 (GMT) [thread overview] Message-ID: <20220615081444.BA998385C33F@sourceware.org> (raw) https://gcc.gnu.org/g:884424353e3577b5f17b7dee4f01be4128943604 commit r10-10838-g884424353e3577b5f17b7dee4f01be4128943604 Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Jun 14 20:42:54 2022 +0100 libstdc++: Backport tests for associative container move constructors libstdc++-v3/ChangeLog: * testsuite/23_containers/map/allocator/move_cons.cc: New test. * testsuite/23_containers/multimap/allocator/move_cons.cc: New test. * testsuite/23_containers/multiset/allocator/move_cons.cc: New test. * testsuite/23_containers/set/allocator/move_cons.cc: New test. Diff: --- .../23_containers/map/allocator/move_cons.cc | 53 ++++++++++++++++++++++ .../23_containers/multimap/allocator/move_cons.cc | 53 ++++++++++++++++++++++ .../23_containers/multiset/allocator/move_cons.cc | 53 ++++++++++++++++++++++ .../23_containers/set/allocator/move_cons.cc | 53 ++++++++++++++++++++++ 4 files changed, 212 insertions(+) diff --git a/libstdc++-v3/testsuite/23_containers/map/allocator/move_cons.cc b/libstdc++-v3/testsuite/23_containers/map/allocator/move_cons.cc new file mode 100644 index 00000000000..b82d3532135 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/allocator/move_cons.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2020-2021 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 +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <map> +#include <string> + +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using Cmp = std::less<int>; + +using __gnu_test::uneq_allocator; + +void test01() +{ + typedef uneq_allocator<std::pair<const int, std::string>> alloc_type; + typedef std::map<int, std::string, Cmp, alloc_type> test_type; + test_type v1(alloc_type(1)); + const char* str = "A long enough string to require dynamic allocation"; + v1 = { { 1, str } }; + + alloc_type a2(2); + test_type v2(std::move(v1), a2); + + VERIFY(1 == v1.get_allocator().get_personality()); + VERIFY(2 == v2.get_allocator().get_personality()); + + VERIFY( v1.empty() ); + VERIFY( v2[1] == str ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/allocator/move_cons.cc b/libstdc++-v3/testsuite/23_containers/multimap/allocator/move_cons.cc new file mode 100644 index 00000000000..37db0f005d1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/allocator/move_cons.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2020-2021 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 +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <map> +#include <string> + +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using Cmp = std::less<int>; + +using __gnu_test::uneq_allocator; + +void test01() +{ + typedef uneq_allocator<std::pair<const int, std::string>> alloc_type; + typedef std::multimap<int, std::string, Cmp, alloc_type> test_type; + test_type v1(alloc_type(1)); + const char* str = "A long enough string to require dynamic allocation"; + v1 = { { 1, str } }; + + alloc_type a2(2); + test_type v2(std::move(v1), a2); + + VERIFY(1 == v1.get_allocator().get_personality()); + VERIFY(2 == v2.get_allocator().get_personality()); + + VERIFY( v1.empty() ); + VERIFY( v2.begin()->second == str ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_cons.cc b/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_cons.cc new file mode 100644 index 00000000000..82dfbc98581 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_cons.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2020-2021 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 +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <set> +#include <string> + +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using Cmp = std::less<std::string>; + +using __gnu_test::uneq_allocator; + +void test01() +{ + typedef uneq_allocator<std::string> alloc_type; + typedef std::multiset<std::string, Cmp, alloc_type> test_type; + test_type v1(alloc_type(1)); + const char* str = "A long enough string to require dynamic allocation"; + v1 = { str }; + + alloc_type a2(2); + test_type v2(std::move(v1), a2); + + VERIFY(1 == v1.get_allocator().get_personality()); + VERIFY(2 == v2.get_allocator().get_personality()); + + VERIFY( v1.count(str) == 0 ); + VERIFY( v2.count(str) == 1 ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/allocator/move_cons.cc b/libstdc++-v3/testsuite/23_containers/set/allocator/move_cons.cc new file mode 100644 index 00000000000..b9b42fcd75c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/allocator/move_cons.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2020-2021 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 +// <http://www.gnu.org/licenses/>. + +// { dg-do run { target c++11 } } + +#include <set> +#include <string> + +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using Cmp = std::less<std::string>; + +using __gnu_test::uneq_allocator; + +void test01() +{ + typedef uneq_allocator<std::string> alloc_type; + typedef std::set<std::string, Cmp, alloc_type> test_type; + test_type v1(alloc_type(1)); + const char* str = "A long enough string to require dynamic allocation"; + v1 = { str }; + + alloc_type a2(2); + test_type v2(std::move(v1), a2); + + VERIFY(1 == v1.get_allocator().get_personality()); + VERIFY(2 == v2.get_allocator().get_personality()); + + VERIFY( v1.count(str) == 0 ); + VERIFY( v2.count(str) == 1 ); +} + + +int main() +{ + test01(); + return 0; +}
reply other threads:[~2022-06-15 8:14 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220615081444.BA998385C33F@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).