diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-03-25 23:25:06 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-03-25 23:25:06 +0000 |
commit | 412989750ddebeb7022ae82df6b8fcb51c47d85a (patch) | |
tree | 761a05f32d72f14f6e0853487486578520c2e07f /llvm/unittests/ADT/DenseMapTest.cpp | |
parent | 221cfdd7b141ebe5c89092ce2c37c928233dce54 (diff) | |
download | llvm-412989750ddebeb7022ae82df6b8fcb51c47d85a.zip llvm-412989750ddebeb7022ae82df6b8fcb51c47d85a.tar.gz llvm-412989750ddebeb7022ae82df6b8fcb51c47d85a.tar.bz2 |
StringMap/DenseMap unittests: use piecewise_construct and ensure no copy occurs.
This makes us no longer relying on move-construction elision by the compiler.
Suggested by D. Blaikie.
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264475
Diffstat (limited to 'llvm/unittests/ADT/DenseMapTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/DenseMapTest.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp index d940677..caeba45 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -377,18 +377,21 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) { CountCopyAndMove::Copy = 0; CountCopyAndMove::Move = 0; for (int i = 0; i < ExpectedMaxInitialEntries; ++i) - Map.insert(std::make_pair(i, CountCopyAndMove())); + Map.insert(std::pair<int, CountCopyAndMove>(std::piecewise_construct, + std::forward_as_tuple(i), + std::forward_as_tuple())); // Check that we didn't grow EXPECT_EQ(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times - EXPECT_EQ(ExpectedMaxInitialEntries * 2, CountCopyAndMove::Move); + EXPECT_EQ(ExpectedMaxInitialEntries, CountCopyAndMove::Move); // Check that no copy occured EXPECT_EQ(0, CountCopyAndMove::Copy); // Adding one extra element should grow the map - CountCopyAndMove::Copy = 0; - CountCopyAndMove::Move = 0; - Map.insert(std::make_pair(ExpectedMaxInitialEntries, CountCopyAndMove())); + Map.insert(std::pair<int, CountCopyAndMove>( + std::piecewise_construct, + std::forward_as_tuple(ExpectedMaxInitialEntries), + std::forward_as_tuple())); // Check that we grew EXPECT_NE(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times @@ -412,12 +415,13 @@ TEST(DenseMapCustomTest, InitialSizeTest) { CountCopyAndMove::Copy = 0; CountCopyAndMove::Move = 0; for (int i = 0; i < Size; ++i) - Map.insert(std::make_pair(i, CountCopyAndMove())); + Map.insert(std::pair<int, CountCopyAndMove>(std::piecewise_construct, + std::forward_as_tuple(i), + std::forward_as_tuple())); // Check that we didn't grow EXPECT_EQ(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times - // This relies on move-construction elision, and cannot be reliably tested. - // EXPECT_EQ(Size * 2, CountCopyAndMove::Move); + EXPECT_EQ(Size, CountCopyAndMove::Move); // Check that no copy occured EXPECT_EQ(0, CountCopyAndMove::Copy); } @@ -455,12 +459,13 @@ TEST(DenseMapCustomTest, ReserveTest) { CountCopyAndMove::Copy = 0; CountCopyAndMove::Move = 0; for (int i = 0; i < Size; ++i) - Map.insert(std::make_pair(i, CountCopyAndMove())); + Map.insert(std::pair<int, CountCopyAndMove>(std::piecewise_construct, + std::forward_as_tuple(i), + std::forward_as_tuple())); // Check that we didn't grow EXPECT_EQ(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times - // This relies on move-construction elision, and cannot be reliably tested. - // EXPECT_EQ(Size * 2, CountCopyAndMove::Move); + EXPECT_EQ(Size, CountCopyAndMove::Move); // Check that no copy occured EXPECT_EQ(0, CountCopyAndMove::Copy); } |