[gcc(refs/users/ppalka/heads/libstdcxx-constrained-algos)] libstdc++: Always return a sentinel<I> from __gnu_test::test_range::end()

Patrick Palka ppalka@gcc.gnu.org
Tue Jan 21 22:41:00 GMT 2020


https://gcc.gnu.org/g:d07b85da9c74421d83afbec2f6294b3770e2ef85

commit d07b85da9c74421d83afbec2f6294b3770e2ef85
Author: Patrick Palka <ppalka@gcc.gnu.org>
Date:   Tue Jan 21 17:00:43 2020 -0500

    libstdc++: Always return a sentinel<I> from __gnu_test::test_range::end()
    
    It seems that in practice std::sentinel_for<I, I> is always true, and so the
    test_range range doesn't help us detect bugs in ranges code in which we wrongly
    assume that a sentinel can be manipulated like an iterator.  Make the test_range
    container more strict by having end() unconditionally return a sentinel<I>.
    
    libstdc++-v3/ChangeLog:
    
    	* testsuite/util/testsuite_iterators.h (__gnu_test::test_range::end):
    	Always return a sentinel<I>.

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_iterators.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index eb15257..6667a3a 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -702,10 +702,7 @@ namespace __gnu_test
       auto end() &
       {
 	using I = decltype(get_iterator(bounds.last));
-	if constexpr (std::sentinel_for<I, I>)
-	  return get_iterator(bounds.last);
-	else
-	  return sentinel<I>{bounds.last};
+	return sentinel<I>{bounds.last};
       }
 
       typename Iter<T>::ContainerType bounds;



More information about the Libstdc++-cvs mailing list