diff --git a/gdb/common/array-view.h b/gdb/common/array-view.h
index 3a09ec720cc..319ea99468d 100644
--- a/gdb/common/array-view.h
+++ b/gdb/common/array-view.h
@@ -174,6 +174,33 @@ private:
   size_type m_size;
 };
 
+/* Compare LHS and RHS for (deep) equality.  That is, whether LHS and
+   RHS have the same sizes, and whether each pair of elements of LHS
+   and RHS at the same position compares equal.  */
+
+template <typename T>
+bool
+operator== (const gdb::array_view<T> &lhs, const gdb::array_view<T> &rhs)
+{
+  if (lhs.size () != rhs.size ())
+    return false;
+
+  for (size_t i = 0; i < lhs.size (); i++)
+    if (!(lhs[i] == rhs[i]))
+      return false;
+
+  return true;
+}
+
+/* Compare two array_views for inequality.  */
+
+template <typename T>
+bool
+operator!= (const gdb::array_view<T> &lhs, const gdb::array_view<T> &rhs)
+{
+  return !(lhs == rhs);
+}
+
 } /* namespace gdb */
 
 #endif
diff --git a/gdb/value.c b/gdb/value.c
index 0a8531614ff..269928d8d04 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -42,6 +42,7 @@
 #include <algorithm>
 #include "completer.h"
 #include "selftest.h"
+#include "common/array-view.h"
 
 /* Definition of a user function.  */
 struct internal_function
@@ -77,6 +78,12 @@ struct range
   {
     return offset < other.offset;
   }
+
+  /* Returns true if THIS is equal to OTHER.  */
+  bool operator== (const range &other) const
+  {
+    return offset == other.offset && length == other.length;
+  }
 };
 
 /* Returns true if the ranges defined by [offset1, offset1+len1) and
@@ -3904,9 +3911,12 @@ isvoid_internal_fn (struct gdbarch *gdbarch,
   return value_from_longest (builtin_type (gdbarch)->builtin_int, ret);
 }
 
+#if GDB_SELF_TEST
 namespace selftests
 {
-static void test_range_contains (void)
+
+static void
+test_range_contains ()
 {
   std::vector<range> ranges;
   range r;
@@ -3947,88 +3957,98 @@ static void test_range_contains (void)
   SELF_CHECK (!ranges_contain (ranges, 26, 3));
 }
 
-/* That that RANGES contains the expected ranges.  EXPECTED_N is the expected
-   length of RANGES.  The variable arguments are pairs of OFFSET/LENGTH
-   corresponding to the expected ranges.  */
+/* Check that RANGES contains the same ranges as EXPECTED.  */
 
-static bool check_ranges_vector (const std::vector<range> &ranges, int expected_n, ...)
+static bool
+check_ranges_vector (gdb::array_view<const range> ranges,
+		     gdb::array_view<const range> expected)
 {
-  if (expected_n != ranges.size ())
-    return false;
-
-  va_list vl;
-  va_start (vl, expected_n);
-
-  bool ret = true;
-  for (const range &r : ranges)
-    {
-      LONGEST offset = va_arg (vl, LONGEST);
-      LONGEST length = va_arg (vl, LONGEST);
-
-      if (r.offset != offset || r.length != length)
-	{
-	  ret = false;
-	  break;
-	}
-    }
-
-  va_end (vl);
-
-  return ret;
+  return ranges == expected;
 }
 
-static void test_insert_into_bit_range_vector (void)
+static void
+test_insert_into_bit_range_vector ()
 {
   std::vector<range> ranges;
 
   /* [10, 14] */
-  insert_into_bit_range_vector (&ranges, 10, 5);
-  SELF_CHECK (check_ranges_vector (ranges, 1,
-				   10, 5));
+  {
+    insert_into_bit_range_vector (&ranges, 10, 5);
+    static const range expected[] = {
+      {10, 5}
+    };
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [10, 14] */
-  insert_into_bit_range_vector (&ranges, 11, 4);
-  SELF_CHECK (check_ranges_vector (ranges, 1,
-				   10, 5));
+  {
+    insert_into_bit_range_vector (&ranges, 11, 4);
+    static const range expected = {10, 5};
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [10, 14] [20, 24] */
-  insert_into_bit_range_vector (&ranges, 20, 5);
-  SELF_CHECK (check_ranges_vector (ranges, 2,
-				   10, 5,
-				   20, 5));
+  {
+    insert_into_bit_range_vector (&ranges, 20, 5);
+    static const range expected[] = {
+      {10, 5},
+      {20, 5},
+    };
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [10, 14] [17, 24] */
-  insert_into_bit_range_vector (&ranges, 17, 5);
-  SELF_CHECK (check_ranges_vector (ranges, 2,
-				   10, 5,
-				   17, 8));
+  {
+    insert_into_bit_range_vector (&ranges, 17, 5);
+    static const range expected[] = {
+      {10, 5},
+      {17, 8},
+    };
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [2, 8] [10, 14] [17, 24] */
-  insert_into_bit_range_vector (&ranges, 2, 7);
-  SELF_CHECK (check_ranges_vector (ranges, 3,
-				   2, 7,
-				   10, 5,
-				   17, 8));
+  {
+    insert_into_bit_range_vector (&ranges, 2, 7);
+    static const range expected[] = {
+      {2, 7},
+      {10, 5},
+      {17, 8},
+    };
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [2, 14] [17, 24] */
-  insert_into_bit_range_vector (&ranges, 9, 1);
-  SELF_CHECK (check_ranges_vector (ranges, 2,
-				   2, 13,
-				   17, 8));
+  {
+    insert_into_bit_range_vector (&ranges, 9, 1);
+    static const range expected[] = {
+      {2, 13},
+      {17, 8},
+    };
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [2, 14] [17, 24] */
-  insert_into_bit_range_vector (&ranges, 9, 1);
-  SELF_CHECK (check_ranges_vector (ranges, 2,
-				   2, 13,
-				   17, 8));
+  {
+    insert_into_bit_range_vector (&ranges, 9, 1);
+    static const range expected[] = {
+      {2, 13},
+      {17, 8},
+    };
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 
   /* [2, 33] */
-  insert_into_bit_range_vector (&ranges, 4, 30);
-  SELF_CHECK (check_ranges_vector (ranges, 1,
-				   2, 32));
-}
+  {
+    insert_into_bit_range_vector (&ranges, 4, 30);
+    static const range expected = {2, 32};
+    SELF_CHECK (check_ranges_vector (ranges, expected));
+  }
 }
 
+} /* namespace selftests */
+#endif /* GDB_SELF_TEST */
+
 void
 _initialize_values (void)
 {
