]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Backport tests for associative container move constructors
authorJonathan Wakely <jwakely@redhat.com>
Tue, 14 Jun 2022 19:42:54 +0000 (20:42 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 15 Jun 2022 08:12:23 +0000 (09:12 +0100)
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.

libstdc++-v3/testsuite/23_containers/map/allocator/move_cons.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/multimap/allocator/move_cons.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/multiset/allocator/move_cons.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/set/allocator/move_cons.cc [new file with mode: 0644]

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 (file)
index 0000000..b82d353
--- /dev/null
@@ -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 (file)
index 0000000..37db0f0
--- /dev/null
@@ -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 (file)
index 0000000..82dfbc9
--- /dev/null
@@ -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 (file)
index 0000000..b9b42fc
--- /dev/null
@@ -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;
+}