From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9717B3858C52; Tue, 23 May 2023 19:12:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9717B3858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684869165; bh=LjkFmz6xmdgfd3C4VGLxtunpg9sugpz220rYV8umCEQ=; h=From:To:Subject:Date:From; b=yJhPIozF79O41F+KliF0gRjHREzcRbp6t8y4ZnywqrlEtcxo3CXlWi8N2XSId4Qi7 lVlNFVJtDP/VPZ5u+edq2VYQuwFxCeaCwD+N+wnSUvl/cU1/r2hjqVH/BPESbmjop9 8VchWJAg9lMTyzEaRBk8vc2XqTT+bkWMiFOxMTmA= From: "aemseemann at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109947] New: std::expected monadic operations do not support move-only error types yet Date: Tue, 23 May 2023 19:12:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: aemseemann at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109947 Bug ID: 109947 Summary: std::expected monadic operations do not support move-only error types yet Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: aemseemann at gmail dot com Target Milestone: --- GCC13 introduce monadic operations for `std::expected`, including r-value ref-qualified overloads, which suggests that it should be possible to use an expected with a move-only value or error type. However, the following [example](https://godbolt.org/z/aoWeaqoGz) does not compile due to an attempt to use unique_ptr's the deleted copy constructor: ```cpp #include #include int main()=20 {=20=20=20 using expected =3D std::expected>; expected e{42}; std::move(e).and_then([](auto&&) -> expected { return 0; }); return 0; } ``` The issue seems to be the use of `std::move(value())` in the &&-qualified overloads of the monadic operations (e.g. [here](https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/inclu= de/std/expected#L880) which selects the `value() &` overload that in turn attempts a copy of the error type in the [exception path](https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/includ= e/std/expected#L740). When replacing the value access with `std::move(*this).value()` the example compiles successfully.=