Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb/unittests: skip mixed constness span tests with libstdc++ debug mode
@ 2026-11-20 20:15 Simon Marchi
  2026-11-20 20:15 ` [PATCH 2/2] gdb: fix out-of-bounds span in append_composite_type_field_raw Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Simon Marchi @ 2026-11-20 20:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-23 15:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 20:15 [PATCH 1/2] gdb/unittests: skip mixed constness span tests with libstdc++ debug mode Simon Marchi
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox