[4/4] Remove operator== and operator!= from gdb::span
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
Commit Message
gdb::span currently provides operator== and operator!=. However,
these aren't part of the C++20 std::span. There, instead, one must
use std::ranges::equal for deep equality.
This patch changes gdb::span to be similar, introducing
gdb::ranges::equal.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31422
---
gdb/dwarf2/read-debug-names.c | 9 ++++++---
gdb/value.c | 2 +-
gdbsupport/span.h | 14 +++++---------
3 files changed, 12 insertions(+), 13 deletions(-)
Comments
On 11/3/26 2:18 PM, Tom Tromey wrote:
> diff --git a/gdbsupport/span.h b/gdbsupport/span.h
> index 01429bcc666..360ff766182 100644
> --- a/gdbsupport/span.h
> +++ b/gdbsupport/span.h
> @@ -229,9 +229,12 @@ void copy (gdb::span<U> src, gdb::span<T> dest)
> RHS have the same sizes, and whether each pair of elements of LHS
> and RHS at the same position compares equal. */
>
> +namespace ranges
> +{
I think the comment above should be inside the "namespace ranges", since
it applies to the function below.
Simon
On 11/10/26 3:03 PM, Simon Marchi wrote:
> On 11/3/26 2:18 PM, Tom Tromey wrote:
>> diff --git a/gdbsupport/span.h b/gdbsupport/span.h
>> index 01429bcc666..360ff766182 100644
>> --- a/gdbsupport/span.h
>> +++ b/gdbsupport/span.h
>> @@ -229,9 +229,12 @@ void copy (gdb::span<U> src, gdb::span<T> dest)
>> RHS have the same sizes, and whether each pair of elements of LHS
>> and RHS at the same position compares equal. */
>>
>> +namespace ranges
>> +{
>
> I think the comment above should be inside the "namespace ranges", since
> it applies to the function below.
Also, maybe the function could be moved to gdbsupport/ranges.h, and
tested in ranges-selftest.c.
While at it (as another patch), we could move
gdb::ranges::views::enumerate to ranges.h as well. Basically all the
functions that are a backport of <ranges>.
Simon
Simon> Also, maybe the function could be moved to gdbsupport/ranges.h, and
Simon> tested in ranges-selftest.c.
There aren't any existing tests for this.
I don't think I'll write them as part of this series.
Simon> While at it (as another patch), we could move
Simon> gdb::ranges::views::enumerate to ranges.h as well. Basically all the
Simon> functions that are a backport of <ranges>.
Someone else will have to do this, v2 of this series is already long.
Tom
On 2026-11-11 10:29, Tom Tromey wrote:
> Simon> Also, maybe the function could be moved to gdbsupport/ranges.h, and
> Simon> tested in ranges-selftest.c.
>
> There aren't any existing tests for this.
> I don't think I'll write them as part of this series.
Ah ok I thought it would be tested in array-view-selftests.c, no
worries.
>
> Simon> While at it (as another patch), we could move
> Simon> gdb::ranges::views::enumerate to ranges.h as well. Basically all the
> Simon> functions that are a backport of <ranges>.
>
> Someone else will have to do this, v2 of this series is already long.
I don't mind doing it once the dust settles.
Simon
Simon> While at it (as another patch), we could move
Simon> gdb::ranges::views::enumerate to ranges.h as well. Basically all the
Simon> functions that are a backport of <ranges>.
>> Someone else will have to do this, v2 of this series is already long.
Simon> I don't mind doing it once the dust settles.
The other thing I've been doing is changing these files to use the std::
versions when __cplusplus allows for it. I think this should probably
be required for future shims. Or at least future c++20 shims, I'm less
sure about whether we want to commit to c++23 stuff yet, I don't even
know if gdb can be built in that mode.
Tom
On 2026-11-11 11:24, Tom Tromey wrote:
> Simon> While at it (as another patch), we could move
> Simon> gdb::ranges::views::enumerate to ranges.h as well. Basically all the
> Simon> functions that are a backport of <ranges>.
>
>>> Someone else will have to do this, v2 of this series is already long.
>
> Simon> I don't mind doing it once the dust settles.
>
> The other thing I've been doing is changing these files to use the std::
> versions when __cplusplus allows for it. I think this should probably
> be required for future shims. Or at least future c++20 shims, I'm less
> sure about whether we want to commit to c++23 stuff yet, I don't even
> know if gdb can be built in that mode.
Note that we could also just use this:
https://github.com/nonstd-lite/span-lite/
It does the "use std::span if available" thing by default, although you
can change it via a macro. It's one header file to drop in gdbsupport,
works well, I've used it (along with other "nonstd-lite" polyfills) in
other projects. License is compatible.
Simon
Simon> Note that we could also just use this:
Simon> https://github.com/nonstd-lite/span-lite/
Simon> It does the "use std::span if available" thing by default, although you
Simon> can change it via a macro. It's one header file to drop in gdbsupport,
Simon> works well, I've used it (along with other "nonstd-lite" polyfills) in
Simon> other projects. License is compatible.
I generally don't like importing code and we already have an
implementation that has worked well for us for years.
Perhaps in a different scenario I would consider it more seriously.
Tom
Tom> I generally don't like importing code and we already have an
Tom> implementation that has worked well for us for years.
Worth noting here that maybe C++20 isn't crazily far off for gdb.
Tom
@@ -817,17 +817,20 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile,
aug_repr.c_str ());
}
- if (augmentation_string == gdb::make_span (dwarf5_augmentation_1))
+ if (gdb::ranges::equal (augmentation_string,
+ gdb::make_span (dwarf5_augmentation_1)))
{
warning (_(".debug_names created by an old version of gdb; ignoring"));
return false;
}
- else if (augmentation_string == gdb::make_span (dwarf5_augmentation_2))
+ else if (gdb::ranges::equal (augmentation_string,
+ gdb::make_span (dwarf5_augmentation_2)))
{
map.augmentation_is_gdb = true;
map.gdb_augmentation_version = 2;
}
- else if (augmentation_string == gdb::make_span (dwarf5_augmentation_3))
+ else if (gdb::ranges::equal (augmentation_string,
+ gdb::make_span (dwarf5_augmentation_3)))
{
map.augmentation_is_gdb = true;
map.gdb_augmentation_version = 3;
@@ -4387,7 +4387,7 @@ static bool
check_ranges_vector (gdb::span<const range> ranges,
gdb::span<const range> expected)
{
- return ranges == expected;
+ return gdb::ranges::equal (ranges, expected);
}
/* Test the insert_into_bit_range_vector function. */
@@ -229,9 +229,12 @@ void copy (gdb::span<U> src, gdb::span<T> dest)
RHS have the same sizes, and whether each pair of elements of LHS
and RHS at the same position compares equal. */
+namespace ranges
+{
+
template <typename T>
bool
-operator== (const gdb::span<T> &lhs, const gdb::span<T> &rhs)
+equal (const gdb::span<T> &lhs, const gdb::span<T> &rhs)
{
if (lhs.size () != rhs.size ())
return false;
@@ -243,14 +246,7 @@ operator== (const gdb::span<T> &lhs, const gdb::span<T> &rhs)
return true;
}
-/* Compare two spans for inequality. */
-
-template <typename T>
-bool
-operator!= (const gdb::span<T> &lhs, const gdb::span<T> &rhs)
-{
- return !(lhs == rhs);
-}
+} /* namespace ranges */
/* Create a span from a pointer to an array and an element
count.