From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v4 13/16] Make gdb::span conform more closely to C++20
Date: Wed, 18 Nov 2026 15:56:14 -0700 [thread overview]
Message-ID: <20261118-span-part-1-v4-13-5ecf901e570b@adacore.com> (raw)
In-Reply-To: <20261118-span-part-1-v4-0-5ecf901e570b@adacore.com>
This removes the single-object constructors from gdb::span, making it
conform more closely to C++20. Also, the cbegin and cend methods are
removed. These do not appear until C++23.
These changes necessitate some unit test changes as well.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31422
---
gdb/unittests/span-selftests.c | 27 +++++----------------------
gdbsupport/span.h | 28 +---------------------------
2 files changed, 6 insertions(+), 49 deletions(-)
diff --git a/gdb/unittests/span-selftests.c b/gdb/unittests/span-selftests.c
index 2cf875d187c..ce137238301 100644
--- a/gdb/unittests/span-selftests.c
+++ b/gdb/unittests/span-selftests.c
@@ -56,13 +56,13 @@ using gdb::span;
/* immutable span */
static_assert ( is_convertible<const T (&) [1], span<const T>> ());
static_assert ( is_convertible<T (&) [1], span<const T>> ());
-static_assert ( is_convertible<const T, span<const T>> ());
-static_assert ( is_convertible<T, span<const T>> ());
+static_assert (!is_convertible<const T, span<const T>> ());
+static_assert (!is_convertible<T, span<const T>> ());
/* mutable span */
static_assert ( is_convertible<T (&) [1], span<T>> ());
static_assert (!is_convertible<const T (&) [1], span<T>> ());
-static_assert ( is_convertible<T, span<T>> ());
+static_assert (!is_convertible<T, span<T>> ());
static_assert (!is_convertible<const T, span<T>> ());
/* While float is implicitly convertible to gdb_byte, we don't want
@@ -93,12 +93,12 @@ static_assert (!is_convertible <C (&)[1], span<B>> ());
/* Same, for elem->view. */
-static_assert ( is_convertible <A, span<A>> ());
+static_assert (!is_convertible <A, span<A>> ());
static_assert (!is_convertible <B, span<A>> ());
static_assert (!is_convertible <C, span<A>> ());
static_assert (!is_convertible <A, span<B>> ());
-static_assert ( is_convertible <B, span<B>> ());
+static_assert (!is_convertible <B, span<B>> ());
static_assert (!is_convertible <C, span<B>> ());
/* Check that there's no container->view conversion for containers of derived
@@ -369,21 +369,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
@@ -507,8 +492,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. */
diff --git a/gdbsupport/span.h b/gdbsupport/span.h
index 483fffb30fc..67cb8fbb36e 100644
--- a/gdbsupport/span.h
+++ b/gdbsupport/span.h
@@ -33,10 +33,7 @@
The main intent of span is to use it as function input
parameter type, making it possible to pass in any sequence of
contiguous objects, irrespective of whether the objects live on the
- stack or heap and what actual container owns them. Implicit
- construction from the element type is supported too, making it easy
- to call functions that expect an array of elements when you only
- have one element (usually on the stack). For example:
+ stack or heap and what actual container owns them. For example:
struct A { .... };
void function (gdb::span<A> as);
@@ -44,12 +41,10 @@
std::vector<A> std_vec = ...;
std::array<A, N> std_array = ...;
A array[] = {...};
- A elem;
function (std_vec);
function (std_array);
function (array);
- function (elem);
Views can be either mutable or const. A const view is simply
created by specifying a const T as span template parameter,
@@ -88,7 +83,6 @@ class span
using reference = T &;
using const_reference = const T &;
using size_type = size_t;
- using const_iterator = const T *;
using iterator = T *;
/* Default construction creates an empty view. */
@@ -96,24 +90,6 @@ class span
: m_array (nullptr), m_size (0)
{}
- /* Create a span over a single object of the type of an
- span element. The created view as size==1. This is
- templated on U to allow constructing a span<const T> over a
- (non-const) T. The "convertible" requirement makes sure that you
- can't create a span<T> over a const T. */
- template<typename U,
- typename = Requires<DecayedConvertible<U>>>
- constexpr span (U &elem) noexcept
- : m_array (&elem), m_size (1)
- {}
-
- /* Same as above, for rvalue references. */
- template<typename U,
- typename = Requires<DecayedConvertible<U>>>
- constexpr span (U &&elem) noexcept
- : m_array (&elem), m_size (1)
- {}
-
/* Create a span from a pointer to an array and an element
count. */
template<typename U,
@@ -172,10 +148,8 @@ class span
constexpr const T *data () const noexcept { return m_array; }
constexpr iterator begin () const noexcept { return m_array; }
- constexpr const_iterator cbegin () const noexcept { return m_array; }
constexpr iterator end () const noexcept { return m_array + m_size; }
- constexpr const_iterator cend () const noexcept { return m_array + m_size; }
constexpr reference operator[] (size_t index) noexcept
{
--
2.56.0
next prev parent reply other threads:[~2026-11-18 22:56 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 22:56 [PATCH v4 00/16] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 01/16] Rename array_view files Tom Tromey
2026-11-18 22:56 ` [PATCH v4 02/16] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 03/16] Rename gdb::make_array_view to gdb::make_span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 04/16] Rename gdb_argv::as_array_view Tom Tromey
2026-11-18 22:56 ` [PATCH v4 05/16] Remove operator== and operator!= from gdb::span Tom Tromey
2026-11-18 22:56 ` [PATCH v4 06/16] Rename span::slice to span::subspan Tom Tromey
2026-11-18 22:56 ` [PATCH v4 07/16] Qualify calls to gdb::copy Tom Tromey
2026-11-18 22:56 ` [PATCH v4 08/16] Add single-argument overloads of process_options et al Tom Tromey
2026-11-18 22:56 ` [PATCH v4 09/16] Remove span from cli-option.c:build_help_option Tom Tromey
2026-11-18 22:56 ` [PATCH v4 10/16] gdb/unittests: use one static_assert per check in span-selftests.c Tom Tromey
2026-11-18 22:56 ` [PATCH v4 11/16] Don't use the single-argument gdb::span constructor Tom Tromey
2026-11-19 3:34 ` Simon Marchi
2026-11-19 3:42 ` Simon Marchi
2026-11-18 22:56 ` [PATCH v4 12/16] Don't turn rvalue reference into a span Tom Tromey
2026-11-19 3:50 ` Simon Marchi
2026-11-19 14:56 ` Tom Tromey
2026-11-18 22:56 ` Tom Tromey [this message]
2026-11-18 22:56 ` [PATCH v4 14/16] Allow the use of C++20 std::ranges in gdbsupport/ranges.h Tom Tromey
2026-11-18 22:56 ` [PATCH v4 15/16] Allow the use of C++20 std::span in gdbsupport/span.h Tom Tromey
2026-11-19 3:52 ` Simon Marchi
2026-11-20 15:52 ` Jan Vrany
2026-11-20 20:15 ` Simon Marchi
2026-11-18 22:56 ` [PATCH v4 16/16] Move gdb::ranges::equal to gdbsupport/ranges.h Tom Tromey
2026-11-19 4:21 ` [PATCH v4 00/16] Rename gdb::array_view to gdb::span Simon Marchi
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=20261118-span-part-1-v4-13-5ecf901e570b@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