From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id VD+pKiVA+Wr2xA4AWB0awg (envelope-from ) for ; Sun, 15 Nov 2026 00:16:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1794719781; bh=KcgJl0uMXRLcPh/oT/oSr5F0uL7hbpC4MWjkW2Zmwpc=; h=Date:Subject:From:To:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=q0A46grl4i8U27K4uEMhs3EDmdzeSJ3LL0bBMp+MF6+kK7XEc6jyshDEuIOswMmXV fTum9eNgMvcofLAUTzfqh8c4CDNAAWvgEsEF/1ObJiBoA1FKtZwwl26zeuiswAd219 mHv+ZxzNbQwkrM1Z/MPmUu4eu70GukhVMGC3fNno= Received: by simark.ca (Postfix, from userid 112) id 9CB0A1E0BC; Sun, 15 Nov 2026 00:16:21 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=ABr9m2ud; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AC0441E043 for ; Sun, 15 Nov 2026 00:16:20 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54F3A4BA9018 for ; Sun, 15 Nov 2026 05:16:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54F3A4BA9018 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=ABr9m2ud Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 42EE04BA798B for ; Sun, 15 Nov 2026 05:15:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42EE04BA798B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 42EE04BA798B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794719752; cv=none; b=xrQnA1gtbaEP8rZNU9xLXIQsi/vW4pPQakz9HufOp/kSatHgGkCbs5BzRJ3wlwkA2sfAWcdZF7fgXeyrC2IMQh2pwSoq+5/atS1vdefpmzE/UOAMWUByhGnesR8qpf4u5xIPvOcFzq/6DnRejWjtt2VCjUSvlqevN0yzRLI1e9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794719752; c=relaxed/simple; bh=KcgJl0uMXRLcPh/oT/oSr5F0uL7hbpC4MWjkW2Zmwpc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=QRFxe+cpSVv/0r4z4rJSlm/WoeBTjg5B3hq0Jr0IEWeOg1rFO8jl3ZJ9RTe9xT12NX4gEgU/4ApHHsChIz6IRI06hKJ5guo0LRMPhZ/ScrW4z6hjc+L7SoMDApZsmw7Csb12j0i5Y89QeqhxtdVL66iz4bdKqMfMtoQrBG/biPE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=ABr9m2ud DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42EE04BA798B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1794719751; bh=KcgJl0uMXRLcPh/oT/oSr5F0uL7hbpC4MWjkW2Zmwpc=; h=Date:Subject:From:To:References:In-Reply-To:From; b=ABr9m2udgnKOtH40e46TxN53qKQcnKWWt/NQ407VrHqV2I374ioxVj8xd5/QXt1mN BBoQ3kzt4Mou1ovM/nsB8Ikd08hcPLYgoeXX2te5ylV6kxB/bbaWGLQapWHTaYvXnz WpsHw8KcBv51Q7+2X6BAuZaZqZcjYurRt8eO4Zio= Received: by simark.ca (Postfix) id 941BA1E043; Sun, 15 Nov 2026 00:15:50 -0500 (EST) Message-ID: <228feb69-232d-4a09-ac25-a014441405e6@simark.ca> Date: Sun, 15 Nov 2026 00:15:49 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 11/15] Change span-selftests.c for C++20 From: Simon Marchi To: Tom Tromey , gdb-patches@sourceware.org References: <20261111-span-part-1-v2-0-cd4e33a8a723@adacore.com> <20261111-span-part-1-v2-11-cd4e33a8a723@adacore.com> <3b7df843-4bde-43dc-a8dd-86cf6a3c3ca8@simark.ca> Content-Language: en-US In-Reply-To: <3b7df843-4bde-43dc-a8dd-86cf6a3c3ca8@simark.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 2026-11-14 23:01, Simon Marchi wrote: > > > On 2026-11-11 10:58, Tom Tromey wrote: >> span-selftests.c has a number of tests that aren't valid for C++20 >> std::span. This patch removes these. > > Could you maybe talk in the commit message about what the general > classes of changes are? My understanding (maybe incomplete): > > - Some were about converting a single element to a span, which > std::span doesn't support. > > - Other changes are about adding a reference (&), not sure what those > are about. > > - Others are about not being able to convert an rvalue-reference to a > span. > > Simon Actually, instead of removing those tests, you could just flip their expected results, although that would probably mean squashing it with the next patch. I think that would be fine though, as the diff in the test would help illustrate the change in behavior brought by the patch. It would also help ensure that gdb::span matches std::span in those regards. The runtime tests: gdb_byte elem = 0; view = elem; SELF_CHECK (check_elem_view (view, elem)); view = std::move (elem); SELF_CHECK (check_elem_view (view, elem)); can become some static_assert to verify it's not possible anymore: static_assert (!std::is_assignable_v &, gdb_byte &>); static_assert (!std::is_assignable_v &, gdb_byte &&>); I gave that a try, but in its current form it's difficult to see exactly which static test fails, because they are just big conjunctions. Switching them to be individual static_asserts would be much clearer. See this patch that I think you could insert just before this one to improve the test. >From d9f641f392d96038e776664803fdf2430b39b944 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 14 Nov 2026 23:48:53 -0500 Subject: [PATCH] gdb/unittests: use one static_assert per check in span-selftests.c To: gdb-patches@sourceware.org The conversion checks in span-selftests.c are written as long chains of "&&" inside constexpr functions, checked by a single static_assert. When one of the checks fails, the compiler only reports that the static_assert failed, which makes it hard to figure out which check is the culprit. Change these to use one static_assert per check, so that the compiler points at the failing one. The checks themselves are unchanged. check_ctor_from_container is a template, so keep it as a function, with the static_asserts in its body. The other checks are moved to namespace scope, in namespaces named after the functions they replace. Change-Id: Iaaa19e3fab701bc672763d85ec29a2f2cd042e22 --- gdb/unittests/span-selftests.c | 142 ++++++++++++++------------------- 1 file changed, 62 insertions(+), 80 deletions(-) diff --git a/gdb/unittests/span-selftests.c b/gdb/unittests/span-selftests.c index 0012d3600d46..eb192bd49fd0 100644 --- a/gdb/unittests/span-selftests.c +++ b/gdb/unittests/span-selftests.c @@ -48,33 +48,29 @@ is_convertible () /* Check for implicit conversion to immutable and mutable views. */ -static constexpr bool -check_convertible () +namespace convertible { - using T = gdb_byte; - using gdb::span; - - return (true - /* immutable span */ - && is_convertible> () - && is_convertible> () - && is_convertible> () - && is_convertible> () - - /* mutable span */ - && is_convertible> () - && !is_convertible> () - && is_convertible> () - && !is_convertible> () - - /* While float is implicitly convertible to gdb_byte, we - don't want implicit float->span - conversion. */ - && !is_convertible> () - && !is_convertible> ()); -} +using T = gdb_byte; +using gdb::span; + +/* immutable span */ +static_assert ( is_convertible> ()); +static_assert ( is_convertible> ()); +static_assert ( is_convertible> ()); +static_assert ( is_convertible> ()); + +/* mutable span */ +static_assert ( is_convertible> ()); +static_assert (!is_convertible> ()); +static_assert ( is_convertible> ()); +static_assert (!is_convertible> ()); -static_assert (check_convertible (), ""); +/* While float is implicitly convertible to gdb_byte, we don't want + implicit float->span conversion. */ +static_assert (!is_convertible> ()); +static_assert (!is_convertible> ()); + +} /* namespace convertible */ namespace no_slicing { @@ -82,35 +78,28 @@ struct A { int i; }; struct B : A { int j; }; struct C : A { int l; }; +using gdb::span; + /* Check that there's no array->view conversion for arrays of derived types or subclasses. */ -static constexpr bool -check () -{ - using gdb::span; - return (true +static_assert ( is_convertible > ()); +static_assert (!is_convertible > ()); +static_assert (!is_convertible > ()); - /* array->view */ +static_assert (!is_convertible > ()); +static_assert ( is_convertible > ()); +static_assert (!is_convertible > ()); - && is_convertible > () - && !is_convertible > () - && !is_convertible > () +/* Same, for elem->view. */ - && !is_convertible > () - && is_convertible > () - && !is_convertible > () +static_assert ( is_convertible > ()); +static_assert (!is_convertible > ()); +static_assert (!is_convertible > ()); - /* elem->view */ - - && is_convertible > () - && !is_convertible > () - && !is_convertible > () - - && !is_convertible > () - && is_convertible > () - && !is_convertible > ()); -} +static_assert (!is_convertible > ()); +static_assert ( is_convertible > ()); +static_assert (!is_convertible > ()); /* Check that there's no container->view conversion for containers of derived types or subclasses. */ @@ -119,15 +108,15 @@ template class Container> static constexpr bool check_ctor_from_container () { - using gdb::span; + static_assert ( is_convertible , span> ()); + static_assert (!is_convertible , span> ()); + static_assert (!is_convertible , span> ()); - return ( is_convertible , span> () - && !is_convertible , span> () - && !is_convertible , span> () + static_assert (!is_convertible , span> ()); + static_assert ( is_convertible , span> ()); + static_assert (!is_convertible , span> ()); - && !is_convertible , span> () - && is_convertible , span> () - && !is_convertible , span> ()); + return true; } } /* namespace no_slicing */ @@ -136,46 +125,39 @@ check_ctor_from_container () check_ctor_from_container. */ template using StdArray1 = std::array; -static_assert (no_slicing::check (), ""); -static_assert (no_slicing::check_ctor_from_container (), ""); -static_assert (no_slicing::check_ctor_from_container (), ""); -static_assert (no_slicing::check_ctor_from_container (), ""); +static_assert (no_slicing::check_ctor_from_container ()); +static_assert (no_slicing::check_ctor_from_container ()); +static_assert (no_slicing::check_ctor_from_container ()); /* Check that span implicitly converts from std::vector. */ -static constexpr bool -check_convertible_from_std_vector () +namespace convertible_from_std_vector { - using gdb::span; - using T = gdb_byte; +using gdb::span; +using T = gdb_byte; - /* Note there's no such thing as std::vector. */ +/* Note there's no such thing as std::vector. */ - return (true - && is_convertible , span> () - && is_convertible , span> ()); -} +static_assert (is_convertible , span> ()); +static_assert (is_convertible , span> ()); -static_assert (check_convertible_from_std_vector (), ""); +} /* namespace convertible_from_std_vector */ /* Check that span implicitly converts from std::array. */ -static constexpr bool -check_convertible_from_std_array () +namespace convertible_from_std_array { - using gdb::span; - using T = gdb_byte; +using gdb::span; +using T = gdb_byte; - /* Note: a non-const T view can't refer to a const T array. */ +/* Note: a non-const T view can't refer to a const T array. */ - return (true - && is_convertible , span> () - && is_convertible , span> () - && !is_convertible , span> () - && is_convertible , span> ()); -} +static_assert ( is_convertible , span> ()); +static_assert ( is_convertible , span> ()); +static_assert (!is_convertible , span> ()); +static_assert ( is_convertible , span> ()); -static_assert (check_convertible_from_std_array (), ""); +} /* namespace convertible_from_std_array */ /* Check that VIEW views C (a container like std::vector/std::array) correctly. */ -- 2.56.0