Add emplace tests for multiset/unordered_multiset.
authorEric Fiselier <eric@efcs.ca>
Tue, 13 Nov 2018 06:30:36 +0000 (06:30 +0000)
committerEric Fiselier <eric@efcs.ca>
Tue, 13 Nov 2018 06:30:36 +0000 (06:30 +0000)
This patch adds tests to ensure that multiset/unordered_multiset's emplace
method correctly constructs the elements without any intervening
constructions.

llvm-svn: 346743

libcxx/test/std/containers/associative/multiset/insert_allocator_requirements.pass.cpp [deleted file]
libcxx/test/std/containers/associative/multiset/insert_emplace_allocator_requirements.pass.cpp [new file with mode: 0644]
libcxx/test/std/containers/set_allocator_requirement_test_templates.h
libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp [deleted file]
libcxx/test/std/containers/unord/unord.multiset/insert_emplace_allocator_requirements.pass.cpp [new file with mode: 0644]

diff --git a/libcxx/test/std/containers/associative/multiset/insert_allocator_requirements.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_allocator_requirements.pass.cpp
deleted file mode 100644 (file)
index a280d10..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <set>
-
-// class multiset
-
-// insert(...)
-
-// UNSUPPORTED: c++98, c++03
-
-#include <set>
-
-#include "container_test_types.h"
-#include "../../set_allocator_requirement_test_templates.h"
-
-int main()
-{
-  testMultisetInsert<TCT::multiset<> >();
-}
diff --git a/libcxx/test/std/containers/associative/multiset/insert_emplace_allocator_requirements.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_emplace_allocator_requirements.pass.cpp
new file mode 100644 (file)
index 0000000..4bd2c88
--- /dev/null
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// class multiset
+
+// insert(...)
+
+// UNSUPPORTED: c++98, c++03
+
+#include <set>
+
+#include "container_test_types.h"
+#include "../../set_allocator_requirement_test_templates.h"
+
+int main()
+{
+  testMultisetInsert<TCT::multiset<> >();
+  testMultisetEmplace<TCT::multiset<> >();
+}
index 2e3346f47e2d2f3505a6d7b4bcc3424019db2611..f82ca7dc8c629b2143c732a94fb34bc1dcf467b0 100644 (file)
@@ -344,11 +344,54 @@ void testMultisetInsert()
   {
     CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
     Container c;
-    ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
+    ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(1) };
     cc->expect<ValueTp&>(3);
     c.insert(std::begin(ValueList), std::end(ValueList));
     assert(!cc->unchecked());
   }
 }
 
+
+template <class Container>
+void testMultisetEmplace()
+{
+  typedef typename Container::value_type ValueTp;
+  typedef Container C;
+  typedef std::pair<typename C::iterator, bool> R;
+  ConstructController* cc = getConstructController();
+  cc->reset();
+  {
+    CHECKPOINT("Testing C::emplace(const value_type&)");
+    Container c;
+    const ValueTp v(42);
+    cc->expect<const ValueTp&>();
+    c.emplace(v);
+    assert(!cc->unchecked());
+  }
+  {
+    CHECKPOINT("Testing C::emplace(value_type&)");
+    Container c;
+    ValueTp v(42);
+    cc->expect<ValueTp&>();
+    c.emplace(v);
+    assert(!cc->unchecked());
+  }
+  {
+    CHECKPOINT("Testing C::emplace(value_type&&)");
+    Container c;
+    ValueTp v(42);
+    cc->expect<ValueTp&&>();
+    c.emplace(std::move(v));
+    assert(!cc->unchecked());
+  }
+  {
+    CHECKPOINT("Testing C::emplace(const value_type&&)");
+    Container c;
+    const ValueTp v(42);
+    cc->expect<const ValueTp&&>();
+    c.emplace(std::move(v));
+    assert(!cc->unchecked());
+  }
+}
+
 #endif
diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp
deleted file mode 100644 (file)
index ad7bc04..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <unordered_set>
-
-// class unordered_multiset
-
-// insert(...)
-
-// UNSUPPORTED: c++98, c++03
-
-#include <unordered_set>
-#include "container_test_types.h"
-#include "../../set_allocator_requirement_test_templates.h"
-
-int main()
-{
-  testMultisetInsert<TCT::unordered_multiset<> >();
-}
diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_emplace_allocator_requirements.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_emplace_allocator_requirements.pass.cpp
new file mode 100644 (file)
index 0000000..4b6e2f7
--- /dev/null
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_set>
+
+// class unordered_multiset
+
+// insert(...)
+
+// UNSUPPORTED: c++98, c++03
+
+#include <unordered_set>
+#include "container_test_types.h"
+#include "../../set_allocator_requirement_test_templates.h"
+
+int main()
+{
+  testMultisetInsert<TCT::unordered_multiset<> >();
+  testMultisetEmplace<TCT::unordered_multiset<> >();
+}