summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/ArrayRefTest.cpp
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2015-09-10 00:05:04 +0000
committerMehdi Amini <mehdi.amini@apple.com>2015-09-10 00:05:04 +0000
commitdefa5465514f024bfe77ade44de346004c11421d (patch)
treeea0547efd38d21760ad0a1afc2ac62a16ab6c1c7 /llvm/unittests/ADT/ArrayRefTest.cpp
parent7540e3a45d232dc216796d22b6b9de5fa584f518 (diff)
downloadbcm5719-llvm-defa5465514f024bfe77ade44de346004c11421d.tar.gz
bcm5719-llvm-defa5465514f024bfe77ade44de346004c11421d.zip
Add makeArrayRef() overload for ArrayRef input (no-op/identity) NFC
The purpose is to allow templated wrapper to work with either ArrayRef or any convertible operation: template<typename Container> void wrapper(const Container &Arr) { impl(makeArrayRef(Arr)); } with Container being a std::vector, a SmallVector, or an ArrayRef. From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 247214
Diffstat (limited to 'llvm/unittests/ADT/ArrayRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/ArrayRefTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index 3ab13a34829..6cbadd6bc22 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -124,4 +124,20 @@ TEST(ArrayRefTest, InitializerList) {
ArgTest12({1, 2});
}
+// Test that makeArrayRef works on ArrayRef (no-op)
+TEST(ArrayRefTest, makeArrayRef) {
+ static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ // No copy expected for non-const ArrayRef (true no-op)
+ ArrayRef<int> AR1(A1);
+ ArrayRef<int> &AR1Ref = makeArrayRef(AR1);
+ EXPECT_EQ(&AR1, &AR1Ref);
+
+ // A copy is expected for non-const ArrayRef (thin copy)
+ const ArrayRef<int> AR2(A1);
+ const ArrayRef<int> &AR2Ref = makeArrayRef(AR2);
+ EXPECT_NE(&AR2Ref, &AR2);
+ EXPECT_TRUE(AR2.equals(AR2Ref));
+}
+
} // end anonymous namespace
OpenPOWER on IntegriCloud