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 +#include #include + +#include "container_test_types.h" #include "count_new.hpp" -#include "MoveOnly.h" +#include "test_macros.h" + +#if TEST_STD_VER >= 11 +template +void PrintInfo(int line, Arg&& arg) +#else +template +void PrintInfo(int line, Arg arg) +#endif +{ + std::cout << "In " << __FILE__ << ":" << line << ":\n " << arg << "\n" << std::endl; +} +#define PRINT(...) PrintInfo(__LINE__, __VA_ARGS__) + +template +void testContainerInsert() +{ + typedef typename Container::value_type ValueTp; + typedef Container C; + typedef std::pair R; + ConstructController* cc = getConstructController(); + cc->reset(); + Container c; + cc->expect(); + + 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 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 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 >(); }