summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-04-29 00:14:27 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-04-29 00:14:27 +0000
commitd24465f443cf37de82362c639a18619e797ff116 (patch)
tree86f6503627097d04985fa630e5075b1a9ce8a394
parent982a589d3a53dfb05130e469a3ad53ae4ee1193d (diff)
downloadbcm5719-llvm-d24465f443cf37de82362c639a18619e797ff116.tar.gz
bcm5719-llvm-d24465f443cf37de82362c639a18619e797ff116.zip
[ADT] Teach PointerUnion to support assignment directly from nullptr to
clear it out. llvm-svn: 207471
-rw-r--r--llvm/include/llvm/ADT/PointerUnion.h18
-rw-r--r--llvm/unittests/ADT/PointerUnionTest.cpp6
2 files changed, 24 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h
index dafd0e05109..a6dddd27762 100644
--- a/llvm/include/llvm/ADT/PointerUnion.h
+++ b/llvm/include/llvm/ADT/PointerUnion.h
@@ -154,6 +154,12 @@ namespace llvm {
"Can't get the address because PointerLikeTypeTraits changes the ptr");
return (PT1 *)Val.getAddrOfPointer();
}
+
+ /// \brief Assignment from nullptr which just clears the union.
+ const PointerUnion &operator=(std::nullptr_t) {
+ Val.initWithPointer(nullptr);
+ return *this;
+ }
/// Assignment operators - Allow assigning into this union from either
/// pointer type, setting the discriminator to remember what it came from.
@@ -298,6 +304,12 @@ namespace llvm {
if (is<T>()) return get<T>();
return T();
}
+
+ /// \brief Assignment from nullptr which just clears the union.
+ const PointerUnion3 &operator=(std::nullptr_t) {
+ Val = nullptr;
+ return *this;
+ }
/// Assignment operators - Allow assigning into this union from either
/// pointer type, setting the discriminator to remember what it came from.
@@ -407,6 +419,12 @@ namespace llvm {
if (is<T>()) return get<T>();
return T();
}
+
+ /// \brief Assignment from nullptr which just clears the union.
+ const PointerUnion4 &operator=(std::nullptr_t) {
+ Val = nullptr;
+ return *this;
+ }
/// Assignment operators - Allow assigning into this union from either
/// pointer type, setting the discriminator to remember what it came from.
diff --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp
index 23a833310d2..3bfb79cee49 100644
--- a/llvm/unittests/ADT/PointerUnionTest.cpp
+++ b/llvm/unittests/ADT/PointerUnionTest.cpp
@@ -46,6 +46,12 @@ TEST_F(PointerUnionTest, Null) {
EXPECT_TRUE((bool)a);
EXPECT_TRUE((bool)b);
EXPECT_FALSE(n);
+
+ EXPECT_NE(n, b);
+ EXPECT_EQ(b, c);
+ b = nullptr;
+ EXPECT_EQ(n, b);
+ EXPECT_NE(b, c);
}
TEST_F(PointerUnionTest, Is) {
OpenPOWER on IntegriCloud