public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hewillk at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/111550] The range adaptor closure object generated by adaptor(args...) is not a perfect forwarding call wrapper
Date: Sun, 24 Sep 2023 10:14:51 +0000	[thread overview]
Message-ID: <bug-111550-4-qDmjoXTMku@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111550-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from 康桓瑋 <hewillk at gmail dot com> ---
Let me report another issue I observed on this PR. 

According to [range.adaptor.object], adaptor(args...) uses
std​::​forward<decltype((args))>(args).. . to forward arguments into the call
wrapper's decayed member, whereas libstdc++ unconditionally uses std::moves,
which causes the following code to be rejected:

https://godbolt.org/z/EYoxzfWKn

  #include <ranges>

  struct NonMovable {
    NonMovable() = default;
    NonMovable(const NonMovable&) = default;
    NonMovable(NonMovable&&) = delete;
  };

  int main() {
    NonMovable nonmovable;
    auto r = std::views::take(nonmovable); // hard error in libc++ and
lidstdc++
  }

The libc++ implementation uses std::bind_back, so it will also produce a hard
error because std::bind_back requires that the argument must be
move-constructible.

It seems like only MSVC conforms to the standard's wording.

The standard does not require the type of args... here to be move-constructible
like other call wrapper factories (such as
std::bind_front/std::bind_back/std::bind) do, which seems to introduce some
inconsistencies.
Although I don't think such constraint is necessary, and I don't know if it's
worthy of an LWG?

  parent reply	other threads:[~2023-09-24 10:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23 14:06 [Bug libstdc++/111550] New: " hewillk at gmail dot com
2023-09-24  9:33 ` [Bug libstdc++/111550] " redi at gcc dot gnu.org
2023-09-24  9:39 ` hewillk at gmail dot com
2023-09-24 10:14 ` hewillk at gmail dot com [this message]
2024-01-11 18:16 ` ppalka at gcc dot gnu.org
2024-01-13  4:11 ` ppalka at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111550-4-qDmjoXTMku@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).