On 04/06/21 21:46 +0100, Jonathan Wakely wrote:
On 04/06/21 21:44 +0100, Jonathan Wakely wrote:
On 04/06/21 18:03 +0100, Jonathan Wakely wrote:
The implementation of P2091R0 was incomplete, so that some range access
CPOs used perfect forwarding where they should not. This fixes it by
consistently operating on lvalues.

Some additional changes that are not necessary to fix the bug:

Modify the __as_const helper to simplify its usage. Instead of deducing
the value category from its argument, and requiring callers to forward
the argument as the correct category, add a non-deduced template
parameter which is used for the value category and accept the argument
as an lvalue. This means callers say __as_const<T>(t) instead of
__as_const(std::forward<T>(t)).

Always use an lvalue reference type as the template argument for the
_S_noexcept helpers, so that we only instantiate one specialization for
lvalues and rvalues of the same type.

Move some helper concepts and functions from namespace std::__detail
to ranges::__cust_access, to be consistent with the ranges::begin CPO.
This ensures that the __adl_begin concept and the _Begin::operator()
function are in the same namespace, so unqualified lookup is consistent
and the poison pills for begin are visible to both.

Simplified static assertions for arrays, because the expression a+0 is
already ill-formed for an array of incomplete type.

Signed-off-by: Jonathan Wakely <jwak...@redhat.com>

libstdc++-v3/ChangeLog:

        PR libstdc++/100824
        * include/bits/iterator_concepts.h (__detail::__decay_copy)
        (__detail::__member_begin, __detail::__adl_begin): Move to
        namespace ranges::__cust_access.
        (__detail::__ranges_begin): Likewise, and rename to __begin.
        Remove redundant static assertion.
        * include/bits/ranges_base.h (_Begin, _End, _RBegin, _REnd):
        Use lvalue in noexcept specifier.
        (__as_const): Add non-deduced parameter for value category.
        (_CBegin, _CEnd, _CRBegin, _CREnd, _CData): Adjust uses of
        __as_const.
        (__member_size, __adl_size, __member_empty, __size0_empty):
        (__eq_iter_empty, __adl_data): Use lvalue objects in
        requirements.
        (__sentinel_size): Likewise. Add check for conversion to
        unsigned-like.
        (__member_data): Allow non-lvalue types to satisfy the concept,
        but use lvalue object in requirements.
        (_Size, _SSize): Remove forwarding to always use an lvalue.
        (_Data): Likewise. Add static assertion for arrays.
        * testsuite/std/ranges/access/cdata.cc: Adjust expected
        behaviour for rvalues. Add negative tests for ill-formed
        expressions.
        * testsuite/std/ranges/access/data.cc: Likewise.
        * testsuite/std/ranges/access/empty.cc: Adjust expected
        behaviour for rvalues.
        * testsuite/std/ranges/access/size.cc: Likewise.

An additional problem with ranges::data was pointed out in the PR,
fixed with this patch.

And this implements the rest of LWG 3403. The change to the
ranges::ssize constraints was already done by the first patch in this
thread, this fixes the return type.

Aaaaand one more fix, as pointed out in the PR.

Tested x86_64-linux. Committed to trunk.

And this one should also be backported to gcc-11 and gcc-10.



commit 96963713f6a648a0ed890450e02ebdd8ff583b14
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Sat Jun 5 11:42:01 2021

    libstdc++: Fix return type of ranges::ssize for 128-bit integer [PR 100824]
    
    Signed-off-by: Jonathan Wakely <jwak...@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100824
            * include/bits/ranges_base.h (_SSize): Return signed type.
            * testsuite/std/ranges/access/ssize.cc: Check with __int128.

diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h
index e3c3962bcd9..728d3ad2b25 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -447,7 +447,7 @@ namespace ranges
 #if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__
 	  // For strict-ansi modes integral<__int128> is false
 	  else if constexpr (__detail::__is_int128<__size_type>)
-	    return static_cast<unsigned __int128>(__size);
+	    return static_cast<__int128>(__size);
 #endif
 	  else // Must be one of __max_diff_type or __max_size_type.
 	    return __detail::__max_diff_type(__size);
diff --git a/libstdc++-v3/testsuite/std/ranges/access/ssize.cc b/libstdc++-v3/testsuite/std/ranges/access/ssize.cc
index f53f462580c..fdbf245d036 100644
--- a/libstdc++-v3/testsuite/std/ranges/access/ssize.cc
+++ b/libstdc++-v3/testsuite/std/ranges/access/ssize.cc
@@ -85,6 +85,20 @@ test06()
   VERIFY( s == 4 );
 }
 
+void
+test07()
+{
+#ifdef __SIZEOF_INT128__
+  struct R
+  {
+    unsigned __int128 size() const { return 4; }
+  };
+  R r;
+  static_assert( std::same_as<decltype(std::ranges::ssize(r)), __int128> );
+  VERIFY( std::ranges::ssize(r) == 4 );
+#endif
+}
+
 int
 main()
 {
@@ -93,4 +107,5 @@ main()
   test04();
   test05();
   test06();
+  test07();
 }

Reply via email to