public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Add variant type
@ 2022-02-01 14:07 Simon Marchi
  2022-02-01 14:07 ` [PATCH 1/4] gdb: remove internalvar_funcs::destroy Simon Marchi
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Simon Marchi @ 2022-02-01 14:07 UTC (permalink / raw)
  To: gdb-patches

I sometimes encounter situations where I think using std::variant would
be useful.  The benefits would be to be able to use non-POD types in the
alternatives, have them automatically constructed when making an
alternative active, and automatically destructing them when switching to
another alternative of destroying the variant.  Also, the validation of
access to the alternatives, to prevent accessing an alternative that is
not the current one.

However, std::variant is only available in C++17.  I suggest that we
import a variant implementation to allow us to use it right now, a bit
like we did for optional and string_view.  We could maybe import the
implementation from libstdc++, like we did for these last two types, but
that sounds really tedious (we would also want to import any tests).
Instead, we can take advantage of a popular implementation distributed
as a single header file.  I chose this one:

  https://github.com/martinmoene/variant-lite

because it is close to the std implementation, and the license (Boost
Software License) is clear and compatible with the GPL v3.

The first two patches of this series make minor adjustements.

The third patch adds the variant-lite header file, but does not use it
yet.

The fourth patch changes the internalval implementation to use a
variant, to show how it can be used, and so that we can discuss on how
we would like our usage of variant to look like.  This usage will then
probably be used as a template for future uses.

Simon Marchi (4):
  gdb: remove internalvar_funcs::destroy
  gdb: constify parameter of value_copy
  gdbsupport: add variant-lite
  gdb: make internalvar use a variant

 gdb/break-catch-throw.c        |    1 -
 gdb/inferior.c                 |    1 -
 gdb/infrun.c                   |    1 -
 gdb/probe.c                    |    1 -
 gdb/thread.c                   |    2 -
 gdb/tracepoint.c               |    1 -
 gdb/value.c                    |  352 ++--
 gdb/value.h                    |    8 +-
 gdb/windows-tdep.c             |    1 -
 gdbsupport/variant/README      |   11 +
 gdbsupport/variant/variant.hpp | 2742 ++++++++++++++++++++++++++++++++
 11 files changed, 2946 insertions(+), 175 deletions(-)
 create mode 100644 gdbsupport/variant/README
 create mode 100644 gdbsupport/variant/variant.hpp


base-commit: e327c35ef5768789d3ba41a629f178f5eec32790
-- 
2.34.1


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

end of thread, other threads:[~2022-03-16 13:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).