Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v2 11/15] Change span-selftests.c for C++20
Date: Wed, 11 Nov 2026 08:58:59 -0700	[thread overview]
Message-ID: <20261111-span-part-1-v2-11-cd4e33a8a723@adacore.com> (raw)
In-Reply-To: <20261111-span-part-1-v2-0-cd4e33a8a723@adacore.com>

span-selftests.c has a number of tests that aren't valid for C++20
std::span.  This patch removes these.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31422
---
 gdb/unittests/span-selftests.c | 76 ++++++++++--------------------------------
 1 file changed, 18 insertions(+), 58 deletions(-)

diff --git a/gdb/unittests/span-selftests.c b/gdb/unittests/span-selftests.c
index 0012d3600d4..013ff2a6aff 100644
--- a/gdb/unittests/span-selftests.c
+++ b/gdb/unittests/span-selftests.c
@@ -58,20 +58,10 @@ check_convertible ()
 	  /* immutable span */
 	  &&  is_convertible<const T (&) [1],	span<const T>> ()
 	  &&  is_convertible<T (&) [1], 	span<const T>> ()
-	  &&  is_convertible<const T, 		span<const T>> ()
-	  &&  is_convertible<T, 		span<const T>> ()
 
 	  /* mutable span */
 	  &&  is_convertible<T (&) [1], 	span<T>> ()
-	  && !is_convertible<const T (&) [1],	span<T>> ()
-	  &&  is_convertible<T, 		span<T>> ()
-	  && !is_convertible<const T,		span<T>> ()
-
-	  /* While float is implicitly convertible to gdb_byte, we
-	     don't want implicit float->span<gdb_byte>
-	     conversion.  */
-	  && !is_convertible<float, 		span<const T>> ()
-	  && !is_convertible<float, 		span<T>> ());
+	  && !is_convertible<const T (&) [1],	span<T>> ());
 }
 
 static_assert (check_convertible (), "");
@@ -99,17 +89,8 @@ check ()
 
 	  && !is_convertible <A (&)[1], span<B>> ()
 	  &&  is_convertible <B (&)[1], span<B>> ()
-	  && !is_convertible <C (&)[1], span<B>> ()
-
-	  /* elem->view  */
-
-	  &&  is_convertible <A, span<A>> ()
-	  && !is_convertible <B, span<A>> ()
-	  && !is_convertible <C, span<A>> ()
-
-	  && !is_convertible <A, span<B>> ()
-	  &&  is_convertible <B, span<B>> ()
-	  && !is_convertible <C, span<B>> ());
+	  && !is_convertible <C (&)[1], span<B>> ());
+;
 }
 
 /* Check that there's no container->view conversion for containers of derived
@@ -121,13 +102,13 @@ check_ctor_from_container ()
 {
   using gdb::span;
 
-  return (    is_convertible <Container<A>, span<A>> ()
-	  && !is_convertible <Container<B>, span<A>> ()
-	  && !is_convertible <Container<C>, span<A>> ()
+  return (is_convertible <Container<A> &, span<A>> ()
+	  && !is_convertible <Container<B> &, span<A>> ()
+	  && !is_convertible <Container<C> &, span<A>> ()
 
-	  && !is_convertible <Container<A>, span<B>> ()
-	  &&  is_convertible <Container<B>, span<B>> ()
-	  && !is_convertible <Container<C>, span<B>> ());
+	  && !is_convertible <Container<A> &, span<B>> ()
+	  &&  is_convertible <Container<B> &, span<B>> ()
+	  && !is_convertible <Container<C> &, span<B>> ());
 }
 
 } /* namespace no_slicing */
@@ -152,8 +133,8 @@ check_convertible_from_std_vector ()
   /* Note there's no such thing as std::vector<const T>.  */
 
   return (true
-	  &&  is_convertible <std::vector<T>, span<T>> ()
-	  &&  is_convertible <std::vector<T>, span<const T>> ());
+	  &&  is_convertible <std::vector<T> &, span<T>> ()
+	  &&  is_convertible <std::vector<T> &, span<const T>> ());
 }
 
 static_assert (check_convertible_from_std_vector (), "");
@@ -169,10 +150,10 @@ check_convertible_from_std_array ()
   /* Note: a non-const T view can't refer to a const T array.  */
 
   return (true
-	  &&  is_convertible <std::array<T, 1>,		span<T>> ()
-	  &&  is_convertible <std::array<T, 1>,		span<const T>> ()
-	  && !is_convertible <std::array<const T, 1>,	span<T>> ()
-	  &&  is_convertible <std::array<const T, 1>,	span<const T>> ());
+	  &&  is_convertible <std::array<T, 1> &,	span<T>> ()
+	  &&  is_convertible <std::array<T, 1> &,	span<const T>> ()
+	  && !is_convertible <std::array<const T, 1> &,	span<T>> ()
+	  &&  is_convertible <std::array<const T, 1> &,	span<const T>> ());
 }
 
 static_assert (check_convertible_from_std_array (), "");
@@ -382,21 +363,6 @@ check_iterator ()
   SELF_CHECK (sum == 2 + 4 + 6 + 8);
 }
 
-template<typename T>
-static void
-check_const_iterator ()
-{
-  T data[] = {1, 2, 3, 4};
-  gdb::span<T> view (data);
-
-  typename std::decay<T>::type sum = 0;
-  for (typename gdb::span<T>::const_iterator it = view.cbegin ();
-       it != view.cend (); it++)
-    sum += *it;
-
-  SELF_CHECK (sum == 1 + 2 + 3 + 4);
-}
-
 /* Entry point.  */
 
 static void
@@ -440,18 +406,14 @@ run_tests ()
 
     view = vec;
     SELF_CHECK (check_container_view (view, vec));
-    view = std::move (vec);
-    SELF_CHECK (check_container_view (view, vec));
 
     view = array;
     SELF_CHECK (check_container_view (view, array));
-    view = std::move (array);
-    SELF_CHECK (check_container_view (view, array));
 
     gdb_byte elem = 0;
-    view = elem;
+    view = gdb::make_span (elem);
     SELF_CHECK (check_elem_view (view, elem));
-    view = std::move (elem);
+    view = std::move (gdb::make_span (elem));
     SELF_CHECK (check_elem_view (view, elem));
   }
 
@@ -524,8 +486,6 @@ run_tests ()
   check_range_for<gdb_byte> ();
   check_range_for<const gdb_byte> ();
   check_iterator<gdb_byte> ();
-  check_const_iterator<gdb_byte> ();
-  check_const_iterator<const gdb_byte> ();
 
   /* Check that the right ctor overloads are taken when the element is
      a container.  */
@@ -537,7 +497,7 @@ run_tests ()
     SELF_CHECK (view_array.size () == 3);
 
     Vec elem;
-    gdb::span<Vec> view_elem = elem;
+    gdb::span<Vec> view_elem = gdb::make_span (elem);
     SELF_CHECK (view_elem.size () == 1);
   }
 

-- 
2.56.0


  parent reply	other threads:[~2026-11-11 16:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 15:58 [PATCH v2 00/15] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 01/15] Rename array_view files Tom Tromey
2026-11-15  4:09   ` Simon Marchi
2026-11-16 15:55     ` Tom Tromey
2026-11-11 15:58 ` [PATCH v2 02/15] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-15  4:18   ` Simon Marchi
2026-11-11 15:58 ` [PATCH v2 03/15] Rename gdb::make_array_view to gdb::make_span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 04/15] Remove operator== and operator!= from gdb::span Tom Tromey
2026-11-11 15:58 ` [PATCH v2 05/15] Rename span::slice to span::subspan Tom Tromey
2026-11-11 15:58 ` [PATCH v2 06/15] Qualify calls to gdb::copy Tom Tromey
2026-11-11 15:58 ` [PATCH v2 07/15] Add single-argument overloads of process_options et al Tom Tromey
2026-11-11 15:58 ` [PATCH v2 08/15] Remove span from cli-option.c:build_help_option Tom Tromey
2026-11-15  3:40   ` Simon Marchi
2026-11-11 15:58 ` [PATCH v2 09/15] Add gdb::make_span overload and add necessary calls Tom Tromey
2026-11-15  3:53   ` Simon Marchi
2026-11-15  4:35     ` Simon Marchi
2026-11-16 16:55       ` Tom Tromey
2026-11-11 15:58 ` [PATCH v2 10/15] Don't turn rvalue reference into a span Tom Tromey
2026-11-11 15:58 ` Tom Tromey [this message]
2026-11-15  4:01   ` [PATCH v2 11/15] Change span-selftests.c for C++20 Simon Marchi
2026-11-15  5:15     ` Simon Marchi
2026-11-11 15:59 ` [PATCH v2 12/15] Make gdb::span conform more closely to C++20 Tom Tromey
2026-11-11 15:59 ` [PATCH v2 13/15] Allow the use of C++20 std::ranges in gdbsupport/ranges.h Tom Tromey
2026-11-15  5:18   ` Simon Marchi
2026-11-11 15:59 ` [PATCH v2 14/15] Allow the use of C++20 std::span in gdbsupport/span.h Tom Tromey
2026-11-15  4:05   ` Simon Marchi
2026-11-11 15:59 ` [PATCH v2 15/15] Move gdb::ranges::equal to gdbsupport/ranges.h Tom Tromey
2026-11-15  5:21 ` [PATCH v2 00/15] Rename gdb::array_view to gdb::span Simon Marchi
2026-11-17 21:42   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111-span-part-1-v2-11-cd4e33a8a723@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox