From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/2] gdb/unittests: skip mixed constness span tests with libstdc++ debug mode
Date: Fri, 20 Nov 2026 15:15:01 -0500 [thread overview]
Message-ID: <20261120201510.3162938-1-simon.marchi@efficios.com> (raw)
When building GDB in C++20 mode with -D_GLIBCXX_DEBUG, span-selftests.c
fails to compile with:
/usr/include/c++/16/span:196:11: error: no matching function for call to '__valid_range(const unsigned char*&, unsigned char*&)'
In debug mode, the (first, last) constructor of libstdc++'s std::span
validates the range by calling __gnu_debug::__valid_range, which
requires both iterators to have the same type. Constructing a span from
two pointers of different constness is valid C++20, but doesn't compile
in that configuration. I believe this is an instance of this existing
gcc bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100990<F12>
As a workaround, move the mixed constness case at the end of
check_ptr_ptr_ctor to check_ptr_ptr_mixed_cv, and skip the body of
check_ptr_ptr_mixed_cv when building in C++20 mode with _GLIBCXX_DEBUG
defined.
Change-Id: I54ff18ecc2463183ff9a0617a6e06662c1b092c5
---
gdb/unittests/span-selftests.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/gdb/unittests/span-selftests.c b/gdb/unittests/span-selftests.c
index 2317f34d1d63..c29b63a03c27 100644
--- a/gdb/unittests/span-selftests.c
+++ b/gdb/unittests/span-selftests.c
@@ -314,18 +314,21 @@ check_ptr_ptr_ctor ()
SELF_CHECK (view.data () == &data[1]);
SELF_CHECK (view[0] == data[1]);
SELF_CHECK (view[1] == data[2]);
-
- gdb_byte array[] = {0x11, 0x22, 0x33, 0x44};
- const gdb_byte *p1 = array;
- gdb_byte *p2 = array + ARRAY_SIZE (array);
- gdb::span<const gdb_byte> view2 (p1, p2);
}
-/* Check construction with a pair of pointers of mixed constness. */
+/* Check construction with a pair of pointers of mixed constness.
+
+ This is skipped when using libstdc++'s std::span in debug mode,
+ because of this libstdc++ bug requiring the two arguments to have
+ the exact same type:
+
+ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100990#c1
+ */
static void
check_ptr_ptr_mixed_cv ()
{
+#if !defined (_GLIBCXX_DEBUG) || __cplusplus < 202002L
gdb_byte array[] = {0x11, 0x22, 0x33, 0x44};
const gdb_byte *cp = array;
gdb_byte *p = array;
@@ -333,6 +336,12 @@ check_ptr_ptr_mixed_cv ()
gdb::span<const gdb_byte> view2 (p, cp);
SELF_CHECK (view1.empty ());
SELF_CHECK (view2.empty ());
+
+ const gdb_byte *p1 = array;
+ gdb_byte *p2 = array + ARRAY_SIZE (array);
+ gdb::span<const gdb_byte> view3 (p1, p2);
+ SELF_CHECK (view3.size () == ARRAY_SIZE (array));
+#endif
}
/* Check range-for support (i.e., begin()/end()). This is a template
base-commit: f50db130cf4ef292211cdd81a950c8e6469aa476
--
2.56.1
next reply other threads:[~2026-11-20 20:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 20:15 Simon Marchi [this message]
2026-11-20 20:15 ` [PATCH 2/2] gdb: fix out-of-bounds span in append_composite_type_field_raw Simon Marchi
2026-11-20 21:22 ` Tom Tromey
2026-11-21 5:09 ` Simon Marchi
2026-11-20 21:22 ` [PATCH 1/2] gdb/unittests: skip mixed constness span tests with libstdc++ debug mode Tom Tromey
2026-11-21 20:32 ` Andrew Burgess
2026-11-23 15:12 ` 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=20261120201510.3162938-1-simon.marchi@efficios.com \
--to=simon.marchi@efficios.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