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++/100824] New: ranges::size should treat the subexpression as an lvalue
Date: Sat, 29 May 2021 11:17:03 +0000	[thread overview]
Message-ID: <bug-100824-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 100824
           Summary: ranges::size should treat the subexpression as an
                    lvalue
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

The CPO described in [range.access] treats the subexpression E as an lvalue,
but ranges::size, ranges::empty, and ranges::data forward E perfectly, which
makes the following case behavior wrong:

https://godbolt.org/z/7KoT3WE41

#include <ranges>
#include <array>

struct R : std::ranges::view_base {
  constexpr int* begin() & { return nullptr; }
  constexpr int* end() & { return nullptr; }
  constexpr int size() & { return 42; }
};
template <>
inline constexpr bool std::ranges::enable_borrowed_range<R> = true;

// call ranges::end(e) - ranges::begin(e) incorrectly
static_assert(std::ranges::size(R{}));

int main() {
  std::array r{42, 42, 42};
  // call e.data() correctly
  (r | std::views::all).data();

  // call std::to_address(ranges::begin(e)) incorrectly
  std::ranges::data(r | std::views::all);
}

             reply	other threads:[~2021-05-29 11:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-29 11:17 hewillk at gmail dot com [this message]
2021-06-03 15:13 ` [Bug libstdc++/100824] " redi at gcc dot gnu.org
2021-06-04 11:39 ` redi at gcc dot gnu.org
2021-06-04 14:59 ` cvs-commit at gcc dot gnu.org
2021-06-04 16:52 ` hewillk at gmail dot com
2021-06-04 19:18 ` redi at gcc dot gnu.org
2021-06-04 20:42 ` cvs-commit at gcc dot gnu.org
2021-06-04 20:48 ` redi at gcc dot gnu.org
2021-06-05  3:16 ` hewillk at gmail dot com
2021-06-05  6:35 ` redi at gcc dot gnu.org
2021-06-05 10:45 ` cvs-commit at gcc dot gnu.org
2021-06-11 22:25 ` cvs-commit at gcc dot gnu.org
2021-06-11 22:25 ` cvs-commit at gcc dot gnu.org
2021-06-11 22:25 ` cvs-commit at gcc dot gnu.org
2022-09-07 12:32 ` redi at gcc dot gnu.org
2022-09-07 12:32 ` redi 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-100824-4@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).