summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorDaniel Sanders <daniel_l_sanders@apple.com>2019-02-20 18:08:48 +0000
committerDaniel Sanders <daniel_l_sanders@apple.com>2019-02-20 18:08:48 +0000
commit9e302c6231ea3053281d731668c48078d5a0641b (patch)
tree997205f6961f96d84affcd5cba347a4b4d281ac1 /llvm/unittests
parent3316eb5bb8025e67415796f657bfae5e5374afae (diff)
downloadbcm5719-llvm-9e302c6231ea3053281d731668c48078d5a0641b.tar.gz
bcm5719-llvm-9e302c6231ea3053281d731668c48078d5a0641b.zip
Add partial implementation of std::to_address() as llvm::to_address()
Summary: Following on from the review for D58088, this patch provides the prerequisite to_address() implementation that's needed to have pointer_iterator support unique_ptr. The late bound return should be removed once we move to C++14 to better align with the C++20 declaration. Also, this implementation can be removed once we move to C++20 where it's defined as std::to_addres() The std::pointer_traits<>::to_address(p) variations of these overloads has not been implemented. Reviewers: dblaikie, paquette Reviewed By: dblaikie Subscribers: dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58421 llvm-svn: 354491
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/ADT/STLExtrasTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 1db1d58870d..26196fb27ea 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -446,4 +446,27 @@ TEST(STLExtrasTest, splat) {
EXPECT_FALSE(is_splat(V));
}
+TEST(STLExtrasTest, to_address) {
+ int *V1 = new int;
+ EXPECT_EQ(V1, to_address(V1));
+
+ // Check fancy pointer overload for unique_ptr
+ std::unique_ptr<int> V2 = make_unique<int>(0);
+ EXPECT_EQ(V2.get(), to_address(V2));
+
+ V2.reset(V1);
+ EXPECT_EQ(V1, to_address(V2));
+ V2.release();
+
+ // Check fancy pointer overload for shared_ptr
+ std::shared_ptr<int> V3 = std::make_shared<int>(0);
+ std::shared_ptr<int> V4 = V3;
+ EXPECT_EQ(V3.get(), V4.get());
+ EXPECT_EQ(V3.get(), to_address(V3));
+ EXPECT_EQ(V4.get(), to_address(V4));
+
+ V3.reset(V1);
+ EXPECT_EQ(V1, to_address(V3));
+}
+
} // namespace
OpenPOWER on IntegriCloud