public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-1227] libstdc++: Fix helper concept for ranges::data [PR 100824]
Date: Fri,  4 Jun 2021 20:42:57 +0000 (GMT)	[thread overview]
Message-ID: <20210604204257.8EB8639A046D@sourceware.org> (raw)

https://gcc.gnu.org/g:3e5f2425f80aedd00f28235022a2755eb46f310d

commit r12-1227-g3e5f2425f80aedd00f28235022a2755eb46f310d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jun 4 20:25:39 2021 +0100

    libstdc++: Fix helper concept for ranges::data [PR 100824]
    
    We need to decay the result of t.data() before checking if it's a
    pointer.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100824
            * include/bits/ranges_base.h (__member_data): Use __decay_copy.
            * testsuite/std/ranges/access/data.cc: Add testcase from PR.

Diff:
---
 libstdc++-v3/include/bits/ranges_base.h          | 6 ++++--
 libstdc++-v3/testsuite/std/ranges/access/data.cc | 6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h
index 17a421a4927..61d91eb8389 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -495,8 +495,10 @@ namespace ranges
 				    && is_object_v<remove_pointer_t<_Tp>>;
 
     template<typename _Tp>
-      concept __member_data
-	= requires(_Tp& __t) { { __t.data() } -> __pointer_to_object; };
+      concept __member_data = requires(_Tp& __t)
+	{
+	  { __cust_access::__decay_copy(__t.data()) } -> __pointer_to_object;
+	};
 
     template<typename _Tp>
       concept __begin_data = requires(_Tp& __t)
diff --git a/libstdc++-v3/testsuite/std/ranges/access/data.cc b/libstdc++-v3/testsuite/std/ranges/access/data.cc
index 237bbcc76c5..4f16f447f9f 100644
--- a/libstdc++-v3/testsuite/std/ranges/access/data.cc
+++ b/libstdc++-v3/testsuite/std/ranges/access/data.cc
@@ -92,8 +92,12 @@ test03()
   // ranges::data should treat the subexpression as an lvalue
   VERIFY( std::ranges::data(std::move(r)) == &R3::i );
   VERIFY( std::ranges::data(std::move(c)) == &R3::l );
-}
 
+  // PR libstdc++/100824 comment 3
+  // Check for member data() should use decay-copy
+  struct A { int*&& data(); };
+  static_assert( has_data<A&> );
+}
 
 int
 main()


                 reply	other threads:[~2021-06-04 20:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210604204257.8EB8639A046D@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).