[PATCH] D18115: [libcxx] unordered_set: Update test for unnecessary mallocs in insert, NFC

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 11 18:26:55 PST 2016


dexonsmith created this revision.
dexonsmith added a reviewer: EricWF.
dexonsmith added a subscriber: cfe-commits.

Modernize the test from r239666 as a precursor for making similar fixes
to unordered_map.


http://reviews.llvm.org/D18115

Files:
  test/libcxx/containers/unord/unord.set/insert_dup_alloc.pass.cpp

Index: test/libcxx/containers/unord/unord.set/insert_dup_alloc.pass.cpp
===================================================================
--- test/libcxx/containers/unord/unord.set/insert_dup_alloc.pass.cpp
+++ test/libcxx/containers/unord/unord.set/insert_dup_alloc.pass.cpp
@@ -11,38 +11,58 @@
 // unordered_set. See PR12999 http://llvm.org/bugs/show_bug.cgi?id=12999
 
 #include <cassert>
+#include <iostream>
 #include <unordered_set>
+
+#include "container_test_types.h"
 #include "count_new.hpp"
-#include "MoveOnly.h"
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 11
+template <class Arg>
+void PrintInfo(int line, Arg&& arg)
+#else
+template <class Arg>
+void PrintInfo(int line, Arg arg)
+#endif
+{
+  std::cout << "In " << __FILE__ << ":" << line << ":\n    " << arg << "\n" << std::endl;
+}
+#define PRINT(...) PrintInfo(__LINE__, __VA_ARGS__)
+
+template <class Container>
+void testContainerInsert()
+{
+  typedef typename Container::value_type ValueTp;
+  typedef Container C;
+  typedef std::pair<typename C::iterator, bool> R;
+  ConstructController* cc = getConstructController();
+  cc->reset();
+  Container c;
+  cc->expect<ValueTp&&>();
+
+  PRINT("Expect a malloc in initial insertion");
+  assert(c.insert(ValueTp(3)).second);
+  assert(!cc->unchecked());
+  DisableAllocationGuard g;
+
+  PRINT("Checking for mallocs in insert(value_type&&)");
+  assert(!c.insert(ValueTp(3)).second);
+
+  PRINT("Checking for mallocs in insert(value_type&)");
+  {
+    ValueTp v(3);
+    assert(!c.insert(v).second);
+  }
+
+  PRINT("Checking for mallocs in insert(const value_type&)");
+  {
+    const ValueTp v(3);
+    assert(!c.insert(v).second);
+  }
+}
 
 int main()
 {
-    {
-    std::unordered_set<int> s;
-    assert(globalMemCounter.checkNewCalledEq(0));
-
-    for(int i=0; i < 100; ++i)
-        s.insert(3);
-
-    assert(s.size() == 1);
-    assert(s.count(3) == 1);
-    assert(globalMemCounter.checkNewCalledEq(2));
-    }
-    assert(globalMemCounter.checkOutstandingNewEq(0));
-    globalMemCounter.reset();
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    {
-    std::unordered_set<MoveOnly> s;
-    assert(globalMemCounter.checkNewCalledEq(0));
-
-    for(int i=0; i<100; i++)
-        s.insert(MoveOnly(3));
-
-    assert(s.size() == 1);
-    assert(s.count(MoveOnly(3)) == 1);
-    assert(globalMemCounter.checkNewCalledEq(2));
-    }
-    assert(globalMemCounter.checkOutstandingNewEq(0));
-    globalMemCounter.reset();
-#endif
+  testContainerInsert<TCT::unordered_set<> >();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18115.50510.patch
Type: text/x-patch
Size: 2517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160312/3fccb933/attachment-0001.bin>


More information about the cfe-commits mailing list