From patchwork Tue Nov 21 12:04:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lancelot SIX X-Patchwork-Id: 80464 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05A463858414 for ; Tue, 21 Nov 2023 12:07:02 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2074.outbound.protection.outlook.com [40.107.93.74]) by sourceware.org (Postfix) with ESMTPS id E94433858282 for ; Tue, 21 Nov 2023 12:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E94433858282 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E94433858282 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.93.74 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700568361; cv=pass; b=ETTQzMCblaClzwPznvxdakRt7FJ0yRGqfPaNFflFtYYFL4CPYfChCQhvweQx792ohzqA+pIA6TEBkiAscSTOFDyDQSgvP81/fKb970YlNRn0ahFm5xqoQo5n0dGy5pgeuGamJuMMutRuTeu1IS8OoLmLrrOc8F+w+2uNfJbK2LM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700568361; c=relaxed/simple; bh=vv0Z/7CVKxR6/fDDNO77EpGlcg2MpF2LC7nGmiPFV+c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RkxU1J5G7u4VFhaUP2T4daqWxgHkW50s61NHzJ/Kl9+qcwV+DgLrSdWU4/xvE8Y91h3+2CWdF6/cfjxx8qBpZ7vZBfbPtkevylPJ0OdTDe5KTU+JwaXmomrgmNL51oGfmM8VHaCXUJeLD88W2aMKIl5ll9X4RBTjOgc+IspWqw0= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q1da7otRg3QKhAjEGqSFmDUiaOQDsXo4heYH4YxF5Zhh9UPyF5oAOrWP0rL2Ot6S1fJiztmvo2fQ+Qg0nMWhoUPJhlUwbI3I/YqmSPUnNtNkzlec0cRqizhUX5mbvtnwrkMEgywiAA4syoNSA/NWDbdAiKX1HYQ4+NKhV2kL2XosAO2thFjOlP+AkK/CIbjo6G00/DsWfDGjIVyatEgPYlBF6Ew5ZOJrHVwVV7aN/SZjt265F4uSQr+/n1j+PY+NWtNxbEqhYWIdSnsmE0H6NxvKe2DMvi9XoLEMwRo5UrzqALv1DBLnhMzQ79ePWW1yfNdU6hr7XkIalNaFz7Ir4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uaf+OmSL0nsE7a9WVB7+POeS80rwqml9buBtOxcfgjU=; b=XhTpPBUIlChogQHLSYnWz5qcGCX1Cj3yIOV+ToKZ2G06N6VrH7nR7bjDdfLudxy7uqTr5dA2LC6E0kYO7sMXpB4aPsm29rwOVj2s+doeT5R3i7eCz2EvysSskKJ4160Qboo870IRjqmPNbNsNT4LPw6/VqH3IvY5DjdmFLRiblQEYp6xe1wCfAbUm+foyP11YjpIU3EpNt7brcvhVLG901wsbf6i6pg9aLdAEbe0WLTSPv/tfoi1dtlJ+padP49BHBl/tZ8DZMfev9WlB0zdSEaya4ghNxpAPOiEkV1U15SMMTruiYdb57dadqMhzoZQP2kTdzJVG4TxaYtw+Ip3gQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uaf+OmSL0nsE7a9WVB7+POeS80rwqml9buBtOxcfgjU=; b=1DReUBOwfXPBU8n9UQOqMj8MAthhWO0OxzRf7XMzx/EPojPQkDCNXuNlEzvBw+X7l9unBwOFcUolkYBxurAGnt091+dUMpkcIHznFGVEkdlUs2TFOi79SZ39+T7CHekqEUjFbf+IRrvH7mPUXiwz49JpmPRTX7KdVvtLYAMXtZU= Received: from BL1PR13CA0097.namprd13.prod.outlook.com (2603:10b6:208:2b9::12) by DM4PR12MB6134.namprd12.prod.outlook.com (2603:10b6:8:ad::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.27; Tue, 21 Nov 2023 12:05:51 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:208:2b9:cafe::42) by BL1PR13CA0097.outlook.office365.com (2603:10b6:208:2b9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.17 via Frontend Transport; Tue, 21 Nov 2023 12:05:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7025.12 via Frontend Transport; Tue, 21 Nov 2023 12:05:51 +0000 Received: from hpe6u-23.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Tue, 21 Nov 2023 06:05:50 -0600 From: Lancelot Six To: CC: , , Lancelot Six Subject: [COMMITTED PATCH v2 3/9] gdbsupport: remove gdb::optional Date: Tue, 21 Nov 2023 12:04:54 +0000 Message-ID: <20231121120500.1394523-4-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231028204821.fp5hh7bahrmrnpjl@hpe6u-23> References: <20231028204821.fp5hh7bahrmrnpjl@hpe6u-23> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|DM4PR12MB6134:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c05317f-641f-48eb-ce2b-08dbea8a34b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hqZRQU60YNJSkdoOIjZzlnzUKI6yqxZQBqBiDGirDOp23rcZxX0W1AcrB1ApYRexUJNl+wAb+B/ijgQcWZxdJMGH7l/Xnn/HSRKcleAs7Ddl20S4xfSaDmPWaHu+0AHyQlhXGX1zO/KlxvHyiq2Bwj+IYJCydphnwuSZUTX8/ml/0YLyF9Zby0pzKGzDNJOH3WqbzjksbKf6t1sd+3F0SnGbNhdQ729EBygIey03ZlPLZc4B4OnAP6YaCnCqzWn35bNgtmqSAjboWeCsBubRNXSJtj3G05nGytnfBVD8nzTqJ8HdfKhnX2JZM6RUxeChWHfATb82jVcZzerFg3P0M+WLaqHhJgil0NzshKjJ7pwEVDgtR7XmO+d1fLJ6+9CCpDbptMvK+OOv+SQAlEX32Sdlqg7I1E0OKwT+sI/lwsmPvGjpNAlMcrzc7rCjrmTRdjK6iscK45wfij6Jw2TqXjiIoE+lUh/XlrCaRisC2+SqCnpF6cPMTr0fBHPA7fiwksF2+T23d03wFsXGhAmIQiuFk2dAzmqbZDJqWXrvQqi6rTYbBDwlJMZdPID5y9MN+I24oh1/T+zN0RgEifcbYk3AcdAeVVuIgs0SIwIIi3afpyaxu528oVYGsHaXXfz+5Q2IIYKaxeS9jyrcQlY2fLnry4nO1Amq5GKQOvpqYXoinSNF6fUKiX+x4BGxe+nYQ9477j8lrPukdbV2AHNlpUBLTJp9mEeUp9AdXXjFK3yAIZkv92mL3Yz1WkvNNVOwRI7ZnNYuIxXAQs2tg9fmhCihNHebwnx4ITozlQLnhXMYdLkY5c52Ck+OGdoI8r9cBDv4G13/mfNgDXjSY38nQA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(346002)(396003)(39860400002)(376002)(136003)(230273577357003)(230173577357003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(82310400011)(46966006)(40470700004)(36840700001)(356005)(41300700001)(81166007)(30864003)(36860700001)(2906002)(7696005)(82740400003)(5660300002)(86362001)(44832011)(47076005)(36756003)(478600001)(8936002)(4326008)(8676002)(2616005)(40480700001)(6916009)(54906003)(70586007)(316002)(70206006)(1076003)(83380400001)(26005)(16526019)(40460700003)(336012)(426003)(2004002)(36900700001)(559001)(579004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2023 12:05:51.3133 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c05317f-641f-48eb-ce2b-08dbea8a34b0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6134 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org The previous patch migrated all the uses of gdb::optional to use std::optional instead, so gdb::optional can be removed entirely as well as the self-tests which came with it. Change-Id: I96ecd67b850b01be10ef00eb85a78ac647d5adc7 Approved-By: Tom Tromey Approved-By: Pedro Alves --- gdb/Makefile.in | 1 - gdb/unittests/optional-selftests.c | 95 -------- gdb/unittests/optional/assignment/1.cc | 196 ---------------- gdb/unittests/optional/assignment/2.cc | 194 ---------------- gdb/unittests/optional/assignment/3.cc | 157 ------------- gdb/unittests/optional/assignment/4.cc | 157 ------------- gdb/unittests/optional/assignment/5.cc | 81 ------- gdb/unittests/optional/assignment/6.cc | 91 -------- gdb/unittests/optional/assignment/7.cc | 30 --- gdb/unittests/optional/cons/copy.cc | 127 ----------- gdb/unittests/optional/cons/default.cc | 59 ----- gdb/unittests/optional/cons/move.cc | 125 ----------- gdb/unittests/optional/cons/value.cc | 295 ------------------------- gdb/unittests/optional/in_place.cc | 66 ------ gdb/unittests/optional/observers/1.cc | 32 --- gdb/unittests/optional/observers/2.cc | 36 --- gdbsupport/gdb_optional.h | 233 ------------------- 17 files changed, 1975 deletions(-) delete mode 100644 gdb/unittests/optional-selftests.c delete mode 100644 gdb/unittests/optional/assignment/1.cc delete mode 100644 gdb/unittests/optional/assignment/2.cc delete mode 100644 gdb/unittests/optional/assignment/3.cc delete mode 100644 gdb/unittests/optional/assignment/4.cc delete mode 100644 gdb/unittests/optional/assignment/5.cc delete mode 100644 gdb/unittests/optional/assignment/6.cc delete mode 100644 gdb/unittests/optional/assignment/7.cc delete mode 100644 gdb/unittests/optional/cons/copy.cc delete mode 100644 gdb/unittests/optional/cons/default.cc delete mode 100644 gdb/unittests/optional/cons/move.cc delete mode 100644 gdb/unittests/optional/cons/value.cc delete mode 100644 gdb/unittests/optional/in_place.cc delete mode 100644 gdb/unittests/optional/observers/1.cc delete mode 100644 gdb/unittests/optional/observers/2.cc delete mode 100644 gdbsupport/gdb_optional.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 52b08692b52..714564f27b4 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -469,7 +469,6 @@ SELFTESTS_SRCS = \ unittests/memrange-selftests.c \ unittests/offset-type-selftests.c \ unittests/observable-selftests.c \ - unittests/optional-selftests.c \ unittests/packed-selftests.c \ unittests/parallel-for-selftests.c \ unittests/parse-connection-spec-selftests.c \ diff --git a/gdb/unittests/optional-selftests.c b/gdb/unittests/optional-selftests.c deleted file mode 100644 index 51135b8b98c..00000000000 --- a/gdb/unittests/optional-selftests.c +++ /dev/null @@ -1,95 +0,0 @@ -/* Self tests for optional for GDB, the GNU debugger. - - Copyright (C) 2017-2023 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#include "defs.h" -#include "gdbsupport/selftest.h" -#include "gdbsupport/gdb_optional.h" - -/* Used by the included .cc files below. Included here because the - included test files are wrapped in a namespace. */ -#include -#include -#include - -/* libstdc++'s testsuite uses VERIFY. */ -#define VERIFY SELF_CHECK - -/* Used to disable testing features not supported by - std::optional. */ -#define GDB_OPTIONAL - -namespace selftests { -namespace optional { - -/* The actual tests live in separate files, which were originally - copied over from libstdc++'s testsuite. To preserve the structure - and help with comparison with the original tests, the file names - have been preserved, and only minimal modification was done to have - them compile against std::optional instead of std::optional: - - - std::optional->gdb:optional, etc. - - ATTRIBUTE_UNUSED in a few places - - wrap each file in a namespace so they can all be compiled as a - single unit. - - libstdc++'s license and formatting style was preserved. -*/ - -#include "optional/assignment/1.cc" -#include "optional/assignment/2.cc" -#include "optional/assignment/3.cc" -#include "optional/assignment/4.cc" -#include "optional/assignment/5.cc" -#include "optional/assignment/6.cc" -#include "optional/assignment/7.cc" -#include "optional/cons/copy.cc" -#include "optional/cons/default.cc" -#include "optional/cons/move.cc" -#include "optional/cons/value.cc" -#include "optional/in_place.cc" -#include "optional/observers/1.cc" -#include "optional/observers/2.cc" - -static void -run_tests () -{ - assign_1::test (); - assign_2::test (); - assign_3::test (); - assign_4::test (); - assign_5::test (); - assign_6::test (); - assign_7::test (); - cons_copy::test (); - cons_default::test (); - cons_move::test (); - cons_value::test (); - in_place::test (); - observers_1::test (); - observers_2::test (); -} - -} /* namespace optional */ -} /* namespace selftests */ - -void _initialize_optional_selftests (); -void -_initialize_optional_selftests () -{ - selftests::register_test ("optional", selftests::optional::run_tests); -} diff --git a/gdb/unittests/optional/assignment/1.cc b/gdb/unittests/optional/assignment/1.cc deleted file mode 100644 index 6a68f7d4002..00000000000 --- a/gdb/unittests/optional/assignment/1.cc +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_1 { - -struct exception {}; - -static int counter = 0; - -struct mixin_counter -{ - mixin_counter() { ++counter; } - mixin_counter(mixin_counter const&) { ++counter; } - ~mixin_counter() { --counter; } -}; - -struct value_type : private mixin_counter -{ - enum state_type - { - zero, - moved_from, - throwing_construction, - throwing_copy, - throwing_copy_assignment, - throwing_move, - throwing_move_assignment, - threw, - }; - - value_type() = default; - - explicit value_type(state_type state_) - : state(state_) - { - throw_if(throwing_construction); - } - - value_type(value_type const& other) - : state(other.state) - { - throw_if(throwing_copy); - } - - value_type& - operator=(value_type const& other) - { - state = other.state; - throw_if(throwing_copy_assignment); - return *this; - } - - value_type(value_type&& other) - : state(other.state) - { - other.state = moved_from; - throw_if(throwing_move); - } - - value_type& - operator=(value_type&& other) - { - state = other.state; - other.state = moved_from; - throw_if(throwing_move_assignment); - return *this; - } - - void throw_if(state_type match) - { - if(state == match) - { - state = threw; - throw exception {}; - } - } - - state_type state = zero; -}; - -static void -test () -{ - using O = gdb::optional; - using S = value_type::state_type; - auto const make = [](S s = S::zero) { return O { gdb::in_place, s }; }; - - enum outcome_type { nothrow, caught, bad_catch }; - - // Check copy/move assignment for disengaged optional - - // From disengaged optional - { - O o; - VERIFY( !o ); - O p; - o = p; - VERIFY( !o ); - VERIFY( !p ); - } - - { - O o; - VERIFY( !o ); - O p; - o = std::move(p); - VERIFY( !o ); - VERIFY( !p ); - } - -#ifndef GDB_OPTIONAL - { - O o; - VERIFY( !o ); - o = {}; - VERIFY( !o ); - } -#endif - - // From engaged optional - { - O o; - VERIFY( !o ); - O p = make(S::throwing_copy_assignment); - o = p; - VERIFY( o && o->state == S::throwing_copy_assignment ); - VERIFY( p && p->state == S::throwing_copy_assignment ); - } - - { - O o; - VERIFY( !o ); - O p = make(S::throwing_move_assignment); - o = std::move(p); - VERIFY( o && o->state == S::throwing_move_assignment ); - VERIFY( p && p->state == S::moved_from ); - } - - { - outcome_type outcome {}; - O o; - VERIFY( !o ); - O p = make(S::throwing_copy); - - try - { - o = p; - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( outcome == caught ); - VERIFY( !o ); - VERIFY( p && p->state == S::throwing_copy ); - } - - { - outcome_type outcome {}; - O o; - VERIFY( !o ); - O p = make(S::throwing_move); - - try - { - o = std::move(p); - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( outcome == caught ); - VERIFY( !o ); - VERIFY( p && p->state == S::moved_from ); - } - - VERIFY( counter == 0 ); -} - -} // namespace assign_1 diff --git a/gdb/unittests/optional/assignment/2.cc b/gdb/unittests/optional/assignment/2.cc deleted file mode 100644 index 2e63a491920..00000000000 --- a/gdb/unittests/optional/assignment/2.cc +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_2 { - -struct exception {}; - -static int counter = 0; - -struct mixin_counter -{ - mixin_counter() { ++counter; } - mixin_counter(mixin_counter const&) { ++counter; } - ~mixin_counter() { --counter; } -}; - -struct value_type : private mixin_counter -{ - enum state_type - { - zero, - moved_from, - throwing_construction, - throwing_copy, - throwing_copy_assignment, - throwing_move, - throwing_move_assignment, - threw, - }; - - value_type() = default; - - explicit value_type(state_type state_) - : state(state_) - { - throw_if(throwing_construction); - } - - value_type(value_type const& other) - : state(other.state) - { - throw_if(throwing_copy); - } - - value_type& - operator=(value_type const& other) - { - state = other.state; - throw_if(throwing_copy_assignment); - return *this; - } - - value_type(value_type&& other) - : state(other.state) - { - other.state = moved_from; - throw_if(throwing_move); - } - - value_type& - operator=(value_type&& other) - { - state = other.state; - other.state = moved_from; - throw_if(throwing_move_assignment); - return *this; - } - - void throw_if(state_type match) - { - if(state == match) - { - state = threw; - throw exception {}; - } - } - - state_type state = zero; -}; - -static void -test () -{ - using O = gdb::optional; - using S = value_type::state_type; - auto const make = [](S s = S::zero) { return O { gdb::in_place, s }; }; - - enum outcome_type { nothrow, caught, bad_catch }; - - // Check copy/move assignment for engaged optional - - // From disengaged optional - { - O o = make(S::zero); - VERIFY( o ); - O p; - o = p; - VERIFY( !o ); - VERIFY( !p ); - } - - { - O o = make(S::zero); - VERIFY( o ); - O p; - o = std::move(p); - VERIFY( !o ); - VERIFY( !p ); - } - -#ifndef GDB_OPTIONAL - { - O o = make(S::zero); - VERIFY( o ); - o = {}; - VERIFY( !o ); - } -#endif - - // From engaged optional - { - O o = make(S::zero); - VERIFY( o ); - O p = make(S::throwing_copy); - o = p; - VERIFY( o && o->state == S::throwing_copy); - VERIFY( p && p->state == S::throwing_copy); - } - - { - O o = make(S::zero); - VERIFY( o ); - O p = make(S::throwing_move); - o = std::move(p); - VERIFY( o && o->state == S::throwing_move); - VERIFY( p && p->state == S::moved_from); - } - - { - ATTRIBUTE_UNUSED outcome_type outcome {}; - O o = make(S::zero); - VERIFY( o ); - O p = make(S::throwing_copy_assignment); - - try - { - o = p; - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( o && o->state == S::threw); - VERIFY( p && p->state == S::throwing_copy_assignment); - } - - { - ATTRIBUTE_UNUSED outcome_type outcome {}; - O o = make(S::zero); - VERIFY( o ); - O p = make(S::throwing_move_assignment); - - try - { - o = std::move(p); - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( o && o->state == S::threw); - VERIFY( p && p->state == S::moved_from); - } - - VERIFY( counter == 0 ); -} - -} // namespace assign_2 diff --git a/gdb/unittests/optional/assignment/3.cc b/gdb/unittests/optional/assignment/3.cc deleted file mode 100644 index a1d0934fe79..00000000000 --- a/gdb/unittests/optional/assignment/3.cc +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_3 { - -struct exception {}; - -static int counter = 0; - -struct mixin_counter -{ - mixin_counter() { ++counter; } - mixin_counter(mixin_counter const&) { ++counter; } - ~mixin_counter() { --counter; } -}; - -struct value_type : private mixin_counter -{ - enum state_type - { - zero, - moved_from, - throwing_construction, - throwing_copy, - throwing_copy_assignment, - throwing_move, - throwing_move_assignment, - threw, - }; - - value_type() = default; - - explicit value_type(state_type state_) - : state(state_) - { - throw_if(throwing_construction); - } - - value_type(value_type const& other) - : state(other.state) - { - throw_if(throwing_copy); - } - - value_type& - operator=(value_type const& other) - { - state = other.state; - throw_if(throwing_copy_assignment); - return *this; - } - - value_type(value_type&& other) - : state(other.state) - { - other.state = moved_from; - throw_if(throwing_move); - } - - value_type& - operator=(value_type&& other) - { - state = other.state; - other.state = moved_from; - throw_if(throwing_move_assignment); - return *this; - } - - void throw_if(state_type match) - { - if(state == match) - { - state = threw; - throw exception {}; - } - } - - state_type state = zero; -}; - -static void -test () -{ - using O = gdb::optional; - using S = value_type::state_type; - auto const make = [](S s = S::zero) { return value_type { s }; }; - - enum outcome_type { nothrow, caught, bad_catch }; - - // Check value assignment for disengaged optional - - { - O o; - value_type v = make(S::throwing_copy_assignment); - o = v; - VERIFY( o && o->state == S::throwing_copy_assignment ); - } - - { - O o; - value_type v = make(S::throwing_move_assignment); - o = std::move(v); - VERIFY( o && o->state == S::throwing_move_assignment ); - } - - { - ATTRIBUTE_UNUSED outcome_type outcome {}; - O o; - value_type v = make(S::throwing_copy); - - try - { - o = v; - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( !o ); - } - - { - ATTRIBUTE_UNUSED outcome_type outcome {}; - O o; - value_type v = make(S::throwing_move); - - try - { - o = std::move(v); - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( !o ); - } - - VERIFY( counter == 0 ); -} - -} // namespace assign_3 diff --git a/gdb/unittests/optional/assignment/4.cc b/gdb/unittests/optional/assignment/4.cc deleted file mode 100644 index 2ad5978a5b4..00000000000 --- a/gdb/unittests/optional/assignment/4.cc +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_4 { - -struct exception {}; - -static int counter = 0; - -struct mixin_counter -{ - mixin_counter() { ++counter; } - mixin_counter(mixin_counter const&) { ++counter; } - ~mixin_counter() { --counter; } -}; - -struct value_type : private mixin_counter -{ - enum state_type - { - zero, - moved_from, - throwing_construction, - throwing_copy, - throwing_copy_assignment, - throwing_move, - throwing_move_assignment, - threw, - }; - - value_type() = default; - - explicit value_type(state_type state_) - : state(state_) - { - throw_if(throwing_construction); - } - - value_type(value_type const& other) - : state(other.state) - { - throw_if(throwing_copy); - } - - value_type& - operator=(value_type const& other) - { - state = other.state; - throw_if(throwing_copy_assignment); - return *this; - } - - value_type(value_type&& other) - : state(other.state) - { - other.state = moved_from; - throw_if(throwing_move); - } - - value_type& - operator=(value_type&& other) - { - state = other.state; - other.state = moved_from; - throw_if(throwing_move_assignment); - return *this; - } - - void throw_if(state_type match) - { - if(state == match) - { - state = threw; - throw exception {}; - } - } - - state_type state = zero; -}; - -static void -test () -{ - using O = gdb::optional; - using S = value_type::state_type; - auto const make = [](S s = S::zero) { return value_type { s }; }; - - enum outcome_type { nothrow, caught, bad_catch }; - - // Check value assignment for engaged optional - - { - O o = make(); - value_type v = make(S::throwing_copy); - o = v; - VERIFY( o && o->state == S::throwing_copy); - } - - { - O o = make(); - value_type v = make(S::throwing_move); - o = std::move(v); - VERIFY( o && o->state == S::throwing_move); - } - - { - ATTRIBUTE_UNUSED outcome_type outcome {}; - O o = make(); - value_type v = make(S::throwing_copy_assignment); - - try - { - o = v; - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( o && o->state == S::threw ); - } - - { - ATTRIBUTE_UNUSED outcome_type outcome {}; - O o = make(); - value_type v = make(S::throwing_move_assignment); - - try - { - o = std::move(v); - } - catch(exception const&) - { outcome = caught; } - catch(...) - { outcome = bad_catch; } - - VERIFY( o && o->state == S::threw ); - } - - VERIFY( counter == 0 ); -} - -} // namespace assign_4 diff --git a/gdb/unittests/optional/assignment/5.cc b/gdb/unittests/optional/assignment/5.cc deleted file mode 100644 index 85016a27bfa..00000000000 --- a/gdb/unittests/optional/assignment/5.cc +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_5 { - -static int counter = 0; - -struct mixin_counter -{ - mixin_counter() { ++counter; } - mixin_counter(mixin_counter const&) { ++counter; } - ~mixin_counter() { --counter; } -}; - -struct value_type : private mixin_counter { }; - -static void -test () -{ - using O = gdb::optional; - - // Check std::nullopt_t and 'default' (= {}) assignment - -#ifndef GDB_OPTIONAL - { - O o; - o = std::nullopt; - VERIFY( !o ); - } -#endif - -#ifndef GDB_OPTIONAL - { - O o { gdb::in_place }; - o = std::nullopt; - VERIFY( !o ); - } -#endif - -#ifndef GDB_OPTIONAL - { - O o; - o = {}; - VERIFY( !o ); - } -#endif - -#ifndef GDB_OPTIONAL - { - O o { gdb::in_place }; - o = {}; - VERIFY( !o ); - } -#endif - { - gdb::optional> ovi{{1, 2, 3}}; - VERIFY(ovi->size() == 3); - VERIFY((*ovi)[0] == 1 && (*ovi)[1] == 2 && (*ovi)[2] == 3); - ovi = {4, 5, 6, 7}; - VERIFY(ovi->size() == 4); - VERIFY((*ovi)[0] == 4 && (*ovi)[1] == 5 && - (*ovi)[2] == 6 && (*ovi)[3] == 7); - } - VERIFY( counter == 0 ); -} - -} // namespace assign_5 diff --git a/gdb/unittests/optional/assignment/6.cc b/gdb/unittests/optional/assignment/6.cc deleted file mode 100644 index d0ea95fa556..00000000000 --- a/gdb/unittests/optional/assignment/6.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_6 { - -static int counter = 0; - -struct mixin_counter -{ - mixin_counter() { ++counter; } - mixin_counter(mixin_counter const&) { ++counter; } - ~mixin_counter() { --counter; } -}; - -struct value_type : private mixin_counter -{ - value_type() = default; - value_type(int) : state(1) { } - value_type(std::initializer_list, const char*) : state(2) { } - int state = 0; -}; - -static void -test () -{ - using O = gdb::optional; - - // Check emplace - - { - O o; - o.emplace(); - VERIFY( o && o->state == 0 ); - } - { - O o { gdb::in_place, 0 }; - o.emplace(); - VERIFY( o && o->state == 0 ); - } - - { - O o; - o.emplace(0); - VERIFY( o && o->state == 1 ); - } - { - O o { gdb::in_place }; - o.emplace(0); - VERIFY( o && o->state == 1 ); - } - -#ifndef GDB_OPTIONAL - { - O o; - o.emplace({ 'a' }, ""); - VERIFY( o && o->state == 2 ); - } - { - O o { gdb::in_place }; - o.emplace({ 'a' }, ""); - VERIFY( o && o->state == 2 ); - } -#endif - { - O o; - VERIFY(&o.emplace(0) == &*o); -#ifndef GDB_OPTIONAL - VERIFY(&o.emplace({ 'a' }, "") == &*o); -#endif - } - - static_assert( !std::is_constructible, int>(), "" ); - - VERIFY( counter == 0 ); -} - -} // namespace assign_6 diff --git a/gdb/unittests/optional/assignment/7.cc b/gdb/unittests/optional/assignment/7.cc deleted file mode 100644 index a9bd181e317..00000000000 --- a/gdb/unittests/optional/assignment/7.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2016-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace assign_7 { - -static void -test () -{ - gdb::optional o{666}; - VERIFY(o && *o == 666); - o.reset(); - VERIFY(!o); - static_assert(noexcept(std::declval>().reset()), ""); -} - -} // namespace assign_7 diff --git a/gdb/unittests/optional/cons/copy.cc b/gdb/unittests/optional/cons/copy.cc deleted file mode 100644 index 87a08f9a52b..00000000000 --- a/gdb/unittests/optional/cons/copy.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace cons_copy { - -struct tracker -{ - tracker(int value) : value(value) { ++count; } - ~tracker() { --count; } - - tracker(tracker const& other) : value(other.value) { ++count; } - tracker(tracker&& other) : value(other.value) - { - other.value = -1; - ++count; - } - - tracker& operator=(tracker const&) = default; - tracker& operator=(tracker&&) = default; - - int value; - - static int count; -}; - -int tracker::count = 0; - -struct exception { }; - -struct throwing_copy -{ - throwing_copy() = default; - throwing_copy(throwing_copy const&) { throw exception {}; } -}; - -static void -test () -{ - // [20.5.4.1] Constructors - - { - gdb::optional o; - auto copy = o; - VERIFY( !copy ); - VERIFY( !o ); - } - - { - const long val = 0x1234ABCD; - gdb::optional o { gdb::in_place, val}; - auto copy = o; - VERIFY( copy ); - VERIFY( *copy == val ); -#ifndef GDB_OPTIONAL - VERIFY( o && o == val ); -#endif - } - - { - gdb::optional o; - auto copy = o; - VERIFY( !copy ); - VERIFY( tracker::count == 0 ); - VERIFY( !o ); - } - - { - gdb::optional o { gdb::in_place, 333 }; - auto copy = o; - VERIFY( copy ); - VERIFY( copy->value == 333 ); - VERIFY( tracker::count == 2 ); - VERIFY( o && o->value == 333 ); - } - - enum outcome { nothrow, caught, bad_catch }; - - { - outcome result = nothrow; - gdb::optional o; - - try - { - auto copy = o; - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == nothrow ); - } - - { - outcome result = nothrow; - gdb::optional o { gdb::in_place }; - - try - { - auto copy = o; - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == caught ); - } - - VERIFY( tracker::count == 0 ); -} - -} // namespace cons_copy diff --git a/gdb/unittests/optional/cons/default.cc b/gdb/unittests/optional/cons/default.cc deleted file mode 100644 index 6ed99c3b9e5..00000000000 --- a/gdb/unittests/optional/cons/default.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace cons_default { - -struct tracker -{ - tracker() { ++count; } - ~tracker() { --count; } - - tracker(tracker const&) { ++count; } - tracker(tracker&&) { ++count; } - - tracker& operator=(tracker const&) = default; - tracker& operator=(tracker&&) = default; - - static int count; -}; - -int tracker::count = 0; - -static void -test () -{ - // [20.5.4.1] Constructors - - { - gdb::optional o; - VERIFY( !o ); - } - - { - gdb::optional o {}; - VERIFY( !o ); - } - - { - gdb::optional o = {}; - VERIFY( !o ); - } - - VERIFY( tracker::count == 0 ); -} - -} // namespace cons_default diff --git a/gdb/unittests/optional/cons/move.cc b/gdb/unittests/optional/cons/move.cc deleted file mode 100644 index 398784ae7ec..00000000000 --- a/gdb/unittests/optional/cons/move.cc +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace cons_move { - -struct tracker -{ - tracker(int value) : value(value) { ++count; } - ~tracker() { --count; } - - tracker(tracker const& other) : value(other.value) { ++count; } - tracker(tracker&& other) : value(other.value) - { - other.value = -1; - ++count; - } - - tracker& operator=(tracker const&) = default; - tracker& operator=(tracker&&) = default; - - int value; - - static int count; -}; - -int tracker::count = 0; - -struct exception { }; - -struct throwing_move -{ - throwing_move() = default; - throwing_move(throwing_move const&) { throw exception {}; } -}; - -static void -test () -{ - // [20.5.4.1] Constructors - - { - gdb::optional o; - auto moved_to = std::move(o); - VERIFY( !moved_to ); - VERIFY( !o ); - } - - { - const long val = 0x1234ABCD; - gdb::optional o { gdb::in_place, val}; - auto moved_to = std::move(o); - VERIFY( moved_to ); - VERIFY( *moved_to == val ); - VERIFY( o && *o == val ); - } - - { - gdb::optional o; - auto moved_to = std::move(o); - VERIFY( !moved_to ); - VERIFY( tracker::count == 0 ); - VERIFY( !o ); - } - - { - gdb::optional o { gdb::in_place, 333 }; - auto moved_to = std::move(o); - VERIFY( moved_to ); - VERIFY( moved_to->value == 333 ); - VERIFY( tracker::count == 2 ); - VERIFY( o && o->value == -1 ); - } - - enum outcome { nothrow, caught, bad_catch }; - - { - outcome result = nothrow; - gdb::optional o; - - try - { - auto moved_to = std::move(o); - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == nothrow ); - } - - { - outcome result = nothrow; - gdb::optional o { gdb::in_place }; - - try - { - auto moved_to = std::move(o); - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == caught ); - } - - VERIFY( tracker::count == 0 ); -} - -} // namespace cons_move diff --git a/gdb/unittests/optional/cons/value.cc b/gdb/unittests/optional/cons/value.cc deleted file mode 100644 index 7d4fd91cfe6..00000000000 --- a/gdb/unittests/optional/cons/value.cc +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace cons_value { - -struct tracker -{ - tracker(int value) : value(value) { ++count; } - ~tracker() { --count; } - - tracker(tracker const& other) : value(other.value) { ++count; } - tracker(tracker&& other) : value(other.value) - { - other.value = -1; - ++count; - } - - tracker& operator=(tracker const&) = default; - tracker& operator=(tracker&&) = default; - - int value; - - static int count; -}; - -int tracker::count = 0; - -struct exception { }; - -struct throwing_construction -{ - explicit throwing_construction(bool propagate) : propagate(propagate) { } - - throwing_construction(throwing_construction const& other) - : propagate(other.propagate) - { - if(propagate) - throw exception {}; - } - - bool propagate; -}; - -static void -test () -{ - // [20.5.4.1] Constructors - - { - auto i = 0x1234ABCD; - gdb::optional o { i }; - VERIFY( o ); - VERIFY( *o == 0x1234ABCD ); - VERIFY( i == 0x1234ABCD ); - } - - { - auto i = 0x1234ABCD; - gdb::optional o = i; - VERIFY( o ); - VERIFY( *o == 0x1234ABCD ); - VERIFY( i == 0x1234ABCD ); - } - - { - auto i = 0x1234ABCD; - gdb::optional o = { i }; - VERIFY( o ); - VERIFY( *o == 0x1234ABCD ); - VERIFY( i == 0x1234ABCD ); - } - - { - auto i = 0x1234ABCD; - gdb::optional o { std::move(i) }; - VERIFY( o ); - VERIFY( *o == 0x1234ABCD ); - VERIFY( i == 0x1234ABCD ); - } - - { - auto i = 0x1234ABCD; - gdb::optional o = std::move(i); - VERIFY( o ); - VERIFY( *o == 0x1234ABCD ); - VERIFY( i == 0x1234ABCD ); - } - - { - auto i = 0x1234ABCD; - gdb::optional o = { std::move(i) }; - VERIFY( o ); - VERIFY( *o == 0x1234ABCD ); - VERIFY( i == 0x1234ABCD ); - } - -#ifndef GDB_OPTIONAL - { - std::vector v = { 0, 1, 2, 3, 4, 5 }; - gdb::optional> o { v }; - VERIFY( !v.empty() ); - VERIFY( o->size() == 6 ); - } -#endif - - { - std::vector v = { 0, 1, 2, 3, 4, 5 }; - gdb::optional> o = v; - VERIFY( !v.empty() ); - VERIFY( o->size() == 6 ); - } - - { - std::vector v = { 0, 1, 2, 3, 4, 5 }; - gdb::optional> o { v }; - VERIFY( !v.empty() ); - VERIFY( o->size() == 6 ); - } - - { - std::vector v = { 0, 1, 2, 3, 4, 5 }; - gdb::optional> o { std::move(v) }; - VERIFY( v.empty() ); - VERIFY( o->size() == 6 ); - } - - { - std::vector v = { 0, 1, 2, 3, 4, 5 }; - gdb::optional> o = std::move(v); - VERIFY( v.empty() ); - VERIFY( o->size() == 6 ); - } - - { - std::vector v = { 0, 1, 2, 3, 4, 5 }; - gdb::optional> o { std::move(v) }; - VERIFY( v.empty() ); - VERIFY( o->size() == 6 ); - } - - { - tracker t { 333 }; - gdb::optional o = t; - VERIFY( o->value == 333 ); - VERIFY( tracker::count == 2 ); - VERIFY( t.value == 333 ); - } - - { - tracker t { 333 }; - gdb::optional o = std::move(t); - VERIFY( o->value == 333 ); - VERIFY( tracker::count == 2 ); - VERIFY( t.value == -1 ); - } - - enum outcome { nothrow, caught, bad_catch }; - - { - outcome result = nothrow; - throwing_construction t { false }; - - try - { - gdb::optional o { t }; - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == nothrow ); - } - - { - outcome result = nothrow; - throwing_construction t { true }; - - try - { - gdb::optional o { t }; - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == caught ); - } - - { - outcome result = nothrow; - throwing_construction t { false }; - - try - { - gdb::optional o { std::move(t) }; - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == nothrow ); - } - - { - outcome result = nothrow; - throwing_construction t { true }; - - try - { - gdb::optional o { std::move(t) }; - } - catch(exception const&) - { result = caught; } - catch(...) - { result = bad_catch; } - - VERIFY( result == caught ); - } - - { -#ifndef GDB_OPTIONAL - gdb::optional os = "foo"; -#endif - struct X - { - explicit X(int) {} - X& operator=(int) {return *this;} - }; -#ifndef GDB_OPTIONAL - gdb::optional ox{42}; -#endif - gdb::optional oi{42}; -#ifndef GDB_OPTIONAL - gdb::optional ox2{oi}; -#endif - gdb::optional os2; - os2 = "foo"; -#ifndef GDB_OPTIONAL - gdb::optional ox3; - ox3 = 42; - gdb::optional ox4; - ox4 = oi; -#endif - } - { - // no converting construction. -#ifndef GDB_OPTIONAL - gdb::optional oi = gdb::optional(); - VERIFY(!bool(oi)); - gdb::optional os = gdb::optional(); - VERIFY(!bool(os)); -#endif - gdb::optional> ooi = gdb::optional(); - VERIFY(bool(ooi)); - ooi = gdb::optional(); - VERIFY(bool(ooi)); - ooi = gdb::optional(42); - VERIFY(bool(ooi)); - VERIFY(bool(*ooi)); -#ifndef GDB_OPTIONAL - gdb::optional> ooi2 = gdb::optional(); - VERIFY(bool(ooi2)); - ooi2 = gdb::optional(); - VERIFY(bool(ooi2)); - ooi2 = gdb::optional(6); - VERIFY(bool(ooi2)); - VERIFY(bool(*ooi2)); - gdb::optional> ooi3 = gdb::optional(42); - VERIFY(bool(ooi3)); - VERIFY(bool(*ooi3)); - gdb::optional> ooi4 = gdb::optional(6); - VERIFY(bool(ooi4)); - VERIFY(bool(*ooi4)); -#endif - } -} - -} // namespace cons_value diff --git a/gdb/unittests/optional/in_place.cc b/gdb/unittests/optional/in_place.cc deleted file mode 100644 index 067f975a0d3..00000000000 --- a/gdb/unittests/optional/in_place.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace in_place { - -static void -test () -{ - // [20.5.5] In-place construction - { - gdb::optional o { gdb::in_place }; - VERIFY( o ); - VERIFY( *o == int() ); - -#ifndef GDB_OPTIONAL - static_assert( !std::is_convertible>(), "" ); -#endif - } - - { - gdb::optional o { gdb::in_place, 42 }; - VERIFY( o ); - VERIFY( *o == 42 ); - } - - { - gdb::optional> o { gdb::in_place, 18, 4 }; - VERIFY( o ); - VERIFY( o->size() == 18 ); - VERIFY( (*o)[17] == 4 ); - } - -#ifndef GDB_OPTIONAL - { - gdb::optional> o { gdb::in_place, { 18, 4 } }; - VERIFY( o ); - VERIFY( o->size() == 2 ); - VERIFY( (*o)[0] == 18 ); - } -#endif - -#ifndef GDB_OPTIONAL - { - gdb::optional> o { gdb::in_place, { 18, 4 }, std::allocator {} }; - VERIFY( o ); - VERIFY( o->size() == 2 ); - VERIFY( (*o)[0] == 18 ); - } -#endif -} - -} // namespace in_place diff --git a/gdb/unittests/optional/observers/1.cc b/gdb/unittests/optional/observers/1.cc deleted file mode 100644 index 20f4176adf1..00000000000 --- a/gdb/unittests/optional/observers/1.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace observers_1 { - -struct value_type -{ - int i; -}; - -static void -test () -{ - gdb::optional o { value_type { 51 } }; - VERIFY( (*o).i == 51 ); -} - -} // namespace observers_1 diff --git a/gdb/unittests/optional/observers/2.cc b/gdb/unittests/optional/observers/2.cc deleted file mode 100644 index 0ad09ab5011..00000000000 --- a/gdb/unittests/optional/observers/2.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2013-2023 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -namespace observers_2 { - -struct value_type -{ - int i; -}; - -void* operator&(const value_type&) = delete; - -static void -test () -{ - gdb::optional o { value_type { 51 } }; - VERIFY( o->i == 51 ); - VERIFY( o->i == (*o).i ); - VERIFY( &o->i == &(*o).i ); -} - -} // namespace observers_2 diff --git a/gdbsupport/gdb_optional.h b/gdbsupport/gdb_optional.h deleted file mode 100644 index 9b7b7b2f7f4..00000000000 --- a/gdbsupport/gdb_optional.h +++ /dev/null @@ -1,233 +0,0 @@ -/* An optional object. - - Copyright (C) 2017-2023 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef COMMON_GDB_OPTIONAL_H -#define COMMON_GDB_OPTIONAL_H - -#include "gdbsupport/traits.h" - -namespace gdb -{ - -struct in_place_t -{ - explicit in_place_t () = default; -}; - -constexpr gdb::in_place_t in_place {}; - -/* This class attempts to be a compatible subset of std::optional, - which is slated to be available in C++17. This class optionally - holds an object of some type -- by default it is constructed not - holding an object, but later the object can be "emplaced". This is - similar to using std::unique_ptr, but in-object allocation is - guaranteed. - - Unlike std::optional, we currently only support copy/move - construction/assignment of an optional from either exactly - optional or T. I.e., we don't support copy/move - construction/assignment from optional or U, when U is a type - convertible to T. Making that work depending on the definitions of - T and U is somewhat complicated, and currently the users of this - class don't need it. */ - -template -class optional -{ -public: - - constexpr optional () - : m_dummy () - {} - - template - constexpr optional (in_place_t, Args &&... args) - : m_item (std::forward (args)...), - m_instantiated (true) - {} - - ~optional () - { this->reset (); } - - /* Copy and move constructors. */ - - optional (const optional &other) - { - if (other.m_instantiated) - this->emplace (other.get ()); - } - - optional (optional &&other) - noexcept(std::is_nothrow_move_constructible ()) - { - if (other.m_instantiated) - this->emplace (std::move (other.get ())); - } - - constexpr optional (const T &other) - : m_item (other), - m_instantiated (true) - {} - - constexpr optional (T &&other) - noexcept (std::is_nothrow_move_constructible ()) - : m_item (std::move (other)), - m_instantiated (true) - {} - - /* Assignment operators. */ - - optional & - operator= (const optional &other) - { - if (m_instantiated && other.m_instantiated) - this->get () = other.get (); - else - { - if (other.m_instantiated) - this->emplace (other.get ()); - else - this->reset (); - } - - return *this; - } - - optional & - operator= (optional &&other) - noexcept (And, - std::is_nothrow_move_assignable> ()) - { - if (m_instantiated && other.m_instantiated) - this->get () = std::move (other.get ()); - else - { - if (other.m_instantiated) - this->emplace (std::move (other.get ())); - else - this->reset (); - } - return *this; - } - - optional & - operator= (const T &other) - { - if (m_instantiated) - this->get () = other; - else - this->emplace (other); - return *this; - } - - optional & - operator= (T &&other) - noexcept (And, - std::is_nothrow_move_assignable> ()) - { - if (m_instantiated) - this->get () = std::move (other); - else - this->emplace (std::move (other)); - return *this; - } - - template - T &emplace (Args &&... args) - { - this->reset (); - new (&m_item) T (std::forward(args)...); - m_instantiated = true; - return this->get (); - } - - /* Observers. */ - constexpr const T *operator-> () const - { return std::addressof (this->get ()); } - - T *operator-> () - { return std::addressof (this->get ()); } - - constexpr const T &operator* () const & - { return this->get (); } - - T &operator* () & - { return this->get (); } - - T &&operator* () && - { return std::move (this->get ()); } - - constexpr const T &&operator* () const && - { return std::move (this->get ()); } - - constexpr explicit operator bool () const noexcept - { return m_instantiated; } - - constexpr bool has_value () const noexcept - { return m_instantiated; } - - /* 'reset' is a 'safe' operation with no precondition. */ - void reset () noexcept - { - if (m_instantiated) - this->destroy (); - } - -private: - - /* Destroy the object. */ - void destroy () - { - gdb_assert (m_instantiated); - m_instantiated = false; - m_item.~T (); - } - - /* The get operations have m_instantiated as a precondition. */ - T &get () noexcept - { -#if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L - gdb_assert (this->has_value ()); -#endif - return m_item; - } - constexpr const T &get () const noexcept - { -#if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L - gdb_assert (this->has_value ()); -#endif - return m_item; - } - - /* The object. */ - union - { - struct { } m_dummy; - T m_item; - volatile char dont_use; /* Silences -Wmaybe-uninitialized warning, see - PR gcc/80635. */ - }; - - /* True if the object was ever emplaced. */ - bool m_instantiated = false; -}; - -} - -#endif /* COMMON_GDB_OPTIONAL_H */