public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/109947] New: std::expected monadic operations do not support move-only error types yet
@ 2023-05-23 19:12 aemseemann at gmail dot com
  2023-05-23 23:32 ` [Bug libstdc++/109947] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: aemseemann at gmail dot com @ 2023-05-23 19:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109947

            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 <expected>
#include <memory>

int main() 
{   
    using expected = std::expected<int, std::unique_ptr<int>>;

    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/include/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/include/std/expected#L740).

When replacing the value access with `std::move(*this).value()` the example
compiles successfully.

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

end of thread, other threads:[~2023-06-06 22:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23 19:12 [Bug libstdc++/109947] New: std::expected monadic operations do not support move-only error types yet aemseemann at gmail dot com
2023-05-23 23:32 ` [Bug libstdc++/109947] " redi at gcc dot gnu.org
2023-05-23 23:36 ` redi at gcc dot gnu.org
2023-05-24 19:34 ` aemseemann at gmail dot com
2023-05-24 20:25 ` redi at gcc dot gnu.org
2023-05-24 21:16 ` aemseemann at gmail dot com
2023-05-25  8:06 ` redi at gcc dot gnu.org
2023-05-25 16:03 ` redi at gcc dot gnu.org
2023-06-01 22:54 ` redi at gcc dot gnu.org
2023-06-06 19:11 ` aemseemann at gmail dot com
2023-06-06 22:59 ` redi at gcc dot gnu.org

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