public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lsix@lancelotsix.com>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb::array_view slicing/container selftest - test std::array too (Re: [PATCH v2 2/2] Improve gdb::array_view ctor from contiguous containers)
Date: Tue, 9 Nov 2021 21:58:48 +0000	[thread overview]
Message-ID: <20211109215848.h3caszzxf4lztjq7@ubuntu.lan> (raw)
In-Reply-To: <7300bb4f-c171-8646-41ec-3753a77cad4b@palves.net>

On Tue, Nov 09, 2021 at 05:52:20PM +0000, Pedro Alves wrote:
> On 2021-11-08 23:02, Lancelot SIX via Gdb-patches wrote:
> >> Alternatively, you could mirror the comment from the built-in array tests:
> >>
> >> /* Check that there's no container->view conversion for containers of derived
> >>    types or subclasses.  */
> >>
> >>
> >> In any case, this is OK.  Thanks for fixing this!
> > 
> > Hi,
> > 
> > I just pushed this.
> 
> Thanks.  Looking again, I noticed we don't exercise construction from std::array containers,
> unlike other tests.  This adds it.  WDYT?

Hi,

Actually my first version used a fixed size std::array exactly as you
have here.  I went for a std::vector instead in the version I have
submitted to the list so I still test against one of the standard
containers while not having to define StdArray1.

I am absolutely fine including a test with a std::array. It could even
replace the std::vector based test since this test is the only one that
uses this container (in which case the '#include <vector>' line could
also be dropped).

In the end, both options check that the old erroneous behavior that
used to allow slicing now fails to compile. This is the most important
point.

Best,
Lancelot.

> 
> From 5da7a3deab00d81df9c5fa708520fc05d6a22ffa Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Tue, 9 Nov 2021 17:48:50 +0000
> Subject: [PATCH] gdb::array_view slicing/container selftest - test std::array
>  too
> 
> Change-Id: I2141b0b8a09f6521a59908599eb5ba1a19b18dc6
> ---
>  gdb/unittests/array-view-selftests.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/gdb/unittests/array-view-selftests.c b/gdb/unittests/array-view-selftests.c
> index 43b7434d10f..fe211a647b5 100644
> --- a/gdb/unittests/array-view-selftests.c
> +++ b/gdb/unittests/array-view-selftests.c
> @@ -137,8 +137,13 @@ check_ctor_from_container ()
>  
>  } /* namespace no_slicing */
>  
> +/* std::array with only one template argument, so we can pass it to
> +   check_ctor_from_container.  */
> +template<typename T> using StdArray1 = std::array<T, 1>;
> +
>  static_assert (no_slicing::check (), "");
>  static_assert (no_slicing::check_ctor_from_container<std::vector> (), "");
> +static_assert (no_slicing::check_ctor_from_container<StdArray1> (), "");
>  static_assert (no_slicing::check_ctor_from_container<gdb::array_view> (), "");
>  
>  /* Check that array_view implicitly converts from std::vector.  */
> 
> base-commit: f0bbba7886f5dba158a143bebbd0691591f22b9f
> -- 
> 2.26.2
> 

  reply	other threads:[~2021-11-09 21:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20 20:05 [PATCH 0/2] Improve constraints on gdb::array_view::array_view Lancelot SIX
2021-10-20 20:05 ` [PATCH 1/2] Add a const version of gdb_argv:as_array_view Lancelot SIX
2021-10-30  2:03   ` Simon Marchi
2021-10-20 20:05 ` [PATCH 2/2] Improve gdb::array_view ctor from contiguous containers Lancelot SIX
2021-10-30  2:09   ` Simon Marchi
2021-11-02 14:10     ` Tom Tromey
2021-11-02 16:00   ` Pedro Alves
2021-11-02 22:51     ` Lancelot SIX
2021-11-03 22:20     ` [PATCH v2 " Lancelot SIX
2021-11-04 13:04       ` Pedro Alves
2021-11-08 23:02         ` Lancelot SIX
2021-11-09 17:52           ` [PATCH] gdb::array_view slicing/container selftest - test std::array too (Re: [PATCH v2 2/2] Improve gdb::array_view ctor from contiguous containers) Pedro Alves
2021-11-09 21:58             ` Lancelot SIX [this message]
2021-11-09 22:48               ` Pedro Alves

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=20211109215848.h3caszzxf4lztjq7@ubuntu.lan \
    --to=lsix@lancelotsix.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).