public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 4/4] gdb: make internalvar use a variant
Date: Fri, 04 Mar 2022 09:23:11 -0700	[thread overview]
Message-ID: <87bkylu1ow.fsf@tromey.com> (raw)
In-Reply-To: <20220201140717.3046952-5-simon.marchi@polymtl.ca> (Simon Marchi via Gdb-patches's message of "Tue, 1 Feb 2022 09:07:17 -0500")

Simon> The advantage of a variant here is that we can more easily use non-POD
Simon> types in the alternatives.  And since it remembers which alternative is
Simon> the current one, accesses are checked so that accesses to the wrong
Simon> alternative throw an exception (see question about that below).

I was wondering if we really need internalvars that can "switch" like
this.  Like, could we just subclass internalvar instead and get rid of
the "kind" / payload stuff.

[...]
Simon> with some functor + std::visit.

FWIW I tend to dislike the visitor pattern anyhow.  IME it is just a
pain to use well -- lots of callbacks, the code becomes unreadable.

Simon>  - The library uses std::variant if it is available (so, if building
Simon>    with C++17).  I think there are slight differences between the std
Simon>    and nonstd versions of variant.  I can't really explain what they
Simon>    are, I am not expert enough in C++.  But for example, when I had not
Simon>    made my visitor's methods const, the code would compile with
Simon>    std::variant but not nonstd::variant.  This means we could get some
Simon>    occasional build failures if some people build in C++11/14 and others
Simon>    C++17.  One way to avoid this would be to define the macro
Simon>    variant_CONFIG_SELECT_VARIANT so that we always use nonstd::variant,
Simon>    regardless of the C++ version.  The small downside is that we
Simon>    wouldn't be testing against std::variant, so some day in the future
Simon>    we want to make the switch to use std::variant, we'll have some fixes
Simon>    to do.

We already have a problem along these lines with string_view, I think,
where we imported one that allows nullptr, then the standard changed(?).
On the whole I'd prefer we try to stick to the standard stuff, if
possible, because once these divergences come in they seem hard to root
out.

Simon>    With exceptions enabled, bad_variant_access is thrown.  Without
Simon>    exceptions enabled, an assert() fails.  In our context, it would be
Simon>    nice if we could call gdb_assert fails, such that we get the usual
Simon>    "internal error" message if that ever happens.  I don't see an easy
Simon>    way to do this other than modifying the header file itself.

Yeah, not sure what to do about that except write some kind of wrapper.

Tom

  reply	other threads:[~2022-03-04 16:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 14:07 [PATCH 0/4] Add variant type Simon Marchi
2022-02-01 14:07 ` [PATCH 1/4] gdb: remove internalvar_funcs::destroy Simon Marchi
2022-03-04 16:15   ` Tom Tromey
2022-03-06 16:33     ` Simon Marchi
2022-02-01 14:07 ` [PATCH 2/4] gdb: constify parameter of value_copy Simon Marchi
2022-03-04 16:16   ` Tom Tromey
2022-03-06 16:33     ` Simon Marchi
2022-02-01 14:07 ` [PATCH 3/4] gdbsupport: add variant-lite header Simon Marchi
2022-02-01 14:07 ` [PATCH 4/4] gdb: make internalvar use a variant Simon Marchi
2022-03-04 16:23   ` Tom Tromey [this message]
2022-03-07 12:12     ` Pedro Alves
2022-03-16  2:06       ` Simon Marchi
2022-03-16 13:26         ` Pedro Alves
2022-03-16 13:28           ` Simon Marchi
2022-02-03  0:02 ` [PATCH 0/4] Add variant type Andrew Burgess
2022-02-03  1:32   ` Simon Marchi
2022-02-04 12:44     ` Andrew Burgess
2022-02-04 13:19       ` 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=87bkylu1ow.fsf@tromey.com \
    --to=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).