From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 3C41A384B832 for ; Tue, 1 Feb 2022 14:07:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C41A384B832 X-ASG-Debug-ID: 1643724437-0c856e06ad2cc490001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id qTDiKU5uGHmCro4I (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 01 Feb 2022 09:07:17 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id B8CC6441B21; Tue, 1 Feb 2022 09:07:17 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 0/4] Add variant type Date: Tue, 1 Feb 2022 09:07:13 -0500 X-ASG-Orig-Subj: [PATCH 0/4] Add variant type Message-Id: <20220201140717.3046952-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1643724437 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 2422 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.95723 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3607.2 required=5.0 tests=BAYES_00, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 14:07:24 -0000 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