[gcc r11-8556] libstdc++: Fix helper concept for ranges::data [PR 100824]

Jonathan Wakely redi@gcc.gnu.org
Fri Jun 11 22:25:42 GMT 2021


https://gcc.gnu.org/g:950535915868cd0b7f3dbad4321de913f01bddfc

commit r11-8556-g950535915868cd0b7f3dbad4321de913f01bddfc
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.
    
    (cherry picked from commit 3e5f2425f80aedd00f28235022a2755eb46f310d)

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


More information about the Libstdc++-cvs mailing list