From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 6E6B9382FC99; Thu, 24 Nov 2022 16:36:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E6B9382FC99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669307791; bh=TGEMFE7VBIyxvvKcTZW1/38NhuL3r6cEkDsEmLAmCYo=; h=From:To:Subject:Date:From; b=iitsaEDWg3uT9yNNxO0L+rYOtyq4vrh0sHnZYAEw9X6Sv94OSisTibMyHOT/RsyxL NG254UwD61tQaYa/zZl3BC++z+gJv/cbsjfr9c0SzaAyS6Pu3LeKBT6aetEbnK8Eec e+/qA8aIBmq+4evFxtK8iJYsQmlFeLk8eifnTy1A= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-8936] libstdc++: Remove unnecessary variant member in std::expected X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: d9b0e012ab939568f5ccbefc4a68ba515e66f4b5 X-Git-Newrev: 377f954242420c6bba380db400bf89ec677647bc Message-Id: <20221124163631.6E6B9382FC99@sourceware.org> Date: Thu, 24 Nov 2022 16:36:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:377f954242420c6bba380db400bf89ec677647bc commit r12-8936-g377f954242420c6bba380db400bf89ec677647bc Author: Jonathan Wakely Date: Tue Nov 1 13:47:24 2022 +0000 libstdc++: Remove unnecessary variant member in std::expected Hui Xie pointed out that we don't need a dummy member in the union, because all constructors always initialize either _M_val or _M_unex. We still need the _M_void member of the expected specialization, because the constructor has to initialize something when not using the _M_unex member. libstdc++-v3/ChangeLog: * include/std/expected (expected::_M_invalid): Remove. (cherry picked from commit f4874691812bc20e3d8e3302db439c27f30c472c) Diff: --- libstdc++-v3/include/std/expected | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected index 3ee13aa95f6..e491ce41591 100644 --- a/libstdc++-v3/include/std/expected +++ b/libstdc++-v3/include/std/expected @@ -359,7 +359,7 @@ namespace __expected requires is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Er> && (!is_trivially_copy_constructible_v<_Tp> || !is_trivially_copy_constructible_v<_Er>) - : _M_invalid(), _M_has_value(__x._M_has_value) + : _M_has_value(__x._M_has_value) { if (_M_has_value) std::construct_at(__builtin_addressof(_M_val), __x._M_val); @@ -376,7 +376,7 @@ namespace __expected requires is_move_constructible_v<_Tp> && is_move_constructible_v<_Er> && (!is_trivially_move_constructible_v<_Tp> || !is_trivially_move_constructible_v<_Er>) - : _M_invalid(), _M_has_value(__x._M_has_value) + : _M_has_value(__x._M_has_value) { if (_M_has_value) std::construct_at(__builtin_addressof(_M_val), @@ -394,7 +394,7 @@ namespace __expected expected(const expected<_Up, _Gr>& __x) noexcept(__and_v, is_nothrow_constructible<_Er, const _Gr&>>) - : _M_invalid(), _M_has_value(__x._M_has_value) + : _M_has_value(__x._M_has_value) { if (_M_has_value) std::construct_at(__builtin_addressof(_M_val), __x._M_val); @@ -410,7 +410,7 @@ namespace __expected expected(expected<_Up, _Gr>&& __x) noexcept(__and_v, is_nothrow_constructible<_Er, _Gr>>) - : _M_invalid(), _M_has_value(__x._M_has_value) + : _M_has_value(__x._M_has_value) { if (_M_has_value) std::construct_at(__builtin_addressof(_M_val), @@ -890,7 +890,6 @@ namespace __expected } union { - struct { } _M_invalid; _Tp _M_val; _Er _M_unex; };