summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/ArrayRefTest.cpp
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2014-12-31 23:33:18 +0000
committerMichael Gottesman <mgottesman@apple.com>2014-12-31 23:33:18 +0000
commit77b1aa98ed886df65c294d711eb2ca31f39eeee3 (patch)
tree494caac21a90df01e199b9733f09664caa8285fd /llvm/unittests/ADT/ArrayRefTest.cpp
parent0ba09e6b843995837862e841e0184d4af19e1b05 (diff)
downloadbcm5719-llvm-77b1aa98ed886df65c294d711eb2ca31f39eeee3.tar.gz
bcm5719-llvm-77b1aa98ed886df65c294d711eb2ca31f39eeee3.zip
Add an ArrayRef upcasting constructor from ArrayRef<U*> -> ArrayRef<T*> where T is a base of U.
llvm-svn: 225053
Diffstat (limited to 'llvm/unittests/ADT/ArrayRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/ArrayRefTest.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index f9c98a563fa..9cd17f00d9a 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -90,4 +90,39 @@ TEST(ArrayRefTest, ConstConvert) {
a = ArrayRef<int *>(A);
}
+struct A {
+ int data;
+
+ A() : data(0) {}
+};
+
+struct B : A {
+ int data2;
+
+ B() : A(), data2(0) {}
+};
+
+TEST(ArrayRefTest, UpcastConvert) {
+ B Data[5];
+
+ for (unsigned i = 0, e = 5; i != e; ++i) {
+ Data[i].data = i + 5;
+ Data[i].data2 = i + 30;
+ }
+
+ B *DataPtrs[5];
+ for (unsigned i = 0, e = 5; i != e; ++i) {
+ DataPtrs[i] = &Data[i];
+ }
+
+ ArrayRef<B *> BArray(DataPtrs, 5);
+ ArrayRef<A *> AArray(BArray);
+
+ EXPECT_TRUE(AArray.size() == 5);
+ for (unsigned i = 0, e = 5; i != e; ++i) {
+ A *a = AArray[i];
+ EXPECT_TRUE(a->data == int(i + 5));
+ }
+}
+
} // end anonymous namespace
OpenPOWER on IntegriCloud