[PATCH] D23890: Fix ArrayRef initializer_list Ctor Test

Erich Keane via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 25 12:29:53 PDT 2016


erichkeane created this revision.
erichkeane added reviewers: llvm-commits, dblaikie, mehdi_amini, zansari, aaron.ballman.
erichkeane set the repository for this revision to rL LLVM.

The InitializerList test had undefined behavior by creating a dangling pointer to the temporary initializer list.  This patch removes the undefined behavior in the test by creating the initializer list directly.  Additionally, this adds another test to validate the scoped-temporary behavior which is extremely common within the code base.

Repository:
  rL LLVM

https://reviews.llvm.org/D23890

Files:
  unittests/ADT/ArrayRefTest.cpp

Index: unittests/ADT/ArrayRefTest.cpp
===================================================================
--- unittests/ADT/ArrayRefTest.cpp
+++ unittests/ADT/ArrayRefTest.cpp
@@ -134,7 +134,8 @@
 }
 
 TEST(ArrayRefTest, InitializerList) {
-  ArrayRef<int> A = { 0, 1, 2, 3, 4 };
+  std::initializer_list<int> init_list = { 0, 1, 2, 3, 4 };
+  ArrayRef<int> A = init_list;
   for (int i = 0; i < 5; ++i)
     EXPECT_EQ(i, A[i]);
 
@@ -146,6 +147,17 @@
   ArgTest12({1, 2});
 }
 
+static void ArrayRefInitArg(ArrayRef<int> A) {
+  for (int i = 0; i < 5; ++i)
+    EXPECT_EQ(i, A[i]);
+}
+
+// A more realistic test for the Init-list ctor
+TEST(ArrayRefTest, InitializerListTemporary) {
+  ArrayRefInitArg({0, 1, 2, 3, 4 });
+}
+  
+
 // Test that makeArrayRef works on ArrayRef (no-op)
 TEST(ArrayRefTest, makeArrayRef) {
   static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23890.69282.patch
Type: text/x-patch
Size: 874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160825/cf58316e/attachment.bin>


More information about the llvm-commits mailing list