From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 044FA388A832; Wed, 17 Jun 2020 19:35:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 044FA388A832 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592422515; bh=thoTzC9FEJK0YCM7dLcJAOnHwE1kT7yCyFBO/tlwkiA=; h=From:To:Subject:Date:From; b=Sx5yrRSMiPdzZs5FUh2MEY79Eue3T16H2T4Dwhipr+3rollrbK82XpGfcz50FQJMX vEzbqSE30lqLSejE5AuKGP/XSGxkoHn2dFcyTmtRaYW+Mc7EI+Py8QLYamg6/JifOW EscqVGnWZAMffWtdRD+fvHX2e6I5CpweDajo1BHc= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/ranger] libstdc++: Add a test that takes the split_view of a non-forward range X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/devel/ranger X-Git-Oldrev: 1c43ee69f4f6148fff4b5ace80d709d7f8b250d7 X-Git-Newrev: 4512b7d85184c7131e98d29255e53cd2d913ddc2 Message-Id: <20200617193515.044FA388A832@sourceware.org> Date: Wed, 17 Jun 2020 19:35:15 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2020 19:35:15 -0000 https://gcc.gnu.org/g:4512b7d85184c7131e98d29255e53cd2d913ddc2 commit 4512b7d85184c7131e98d29255e53cd2d913ddc2 Author: Patrick Palka Date: Wed Mar 11 11:08:49 2020 -0400 libstdc++: Add a test that takes the split_view of a non-forward range This adds a tests that verifies taking the split_view of a non-forward range works correctly. Doing so revealed a typo in one of _OuterIter's constructors. It also revealed that the default constructor of __gnu_test::test_range::iterator misbehaves, because by delegating to Iter(nullptr, nullptr) we perform a null-pointer deref at runtime in input_iterator_wrapper's constructor due to the ITERATOR_VERIFY check therein. Instead of delegating to this constructor it seems we can just inherit the protected default constructor, which does not contain this ITERATOR_VERIFY check. libstdc++-v3/ChangeLog: * include/std/ranges (split_view::_OuterIter::_OuterIter): Typo fix, 'address' -> 'std::__addressof'. * testsuite/std/ranges/adaptors/split.cc: Test taking the split_view of a non-forward input_range. * testsuite/util/testsuite_iterators.h (output_iterator_wrapper): Make default constructor protected instead of deleted, like with input_iterator_wrapper. (test_range::iterator): Add comment explaining that this type is used only when the underlying wrapper is input_iterator_wrapper or output_iterator_wrapper. Remove delegating defaulted constructor so that the inherited default constructor is used instead. Diff: --- libstdc++-v3/ChangeLog | 12 ++++++++++++ libstdc++-v3/include/std/ranges | 2 +- libstdc++-v3/testsuite/std/ranges/adaptors/split.cc | 20 ++++++++++++++++++++ libstdc++-v3/testsuite/util/testsuite_iterators.h | 14 +++++++++----- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 27ef7e39087..4ff4a0eecc9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,17 @@ 2020-03-11 Patrick Palka + * include/std/ranges (split_view::_OuterIter::_OuterIter): Typo fix, + 'address' -> 'std::__addressof'. + * testsuite/std/ranges/adaptors/split.cc: Test taking the split_view of + a non-forward input_range. + * testsuite/util/testsuite_iterators.h (output_iterator_wrapper): Make + default constructor protected instead of deleted, like with + input_iterator_wrapper. + (test_range::iterator): Add comment explaining that this type is used + only when the underlying wrapper is input_iterator_wrapper or + output_iterator_wrapper. Remove delegating defaulted constructor so + that the inherited default constructor is used instead. + LWG 3286 ranges::size is not required to be valid after a call to ranges::begin on an input range * include/std/ranges (subrange::subrange): Split single-argument diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 5b06a9e6f43..8f91598c26e 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -2785,7 +2785,7 @@ namespace views constexpr explicit _OuterIter(_Parent& __parent) requires (!forward_range<_Base>) - : _M_parent(address(__parent)) + : _M_parent(std::__addressof(__parent)) { } constexpr diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc index abdbfb41d8b..fe895827fc5 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc @@ -27,6 +27,7 @@ using __gnu_test::test_range; using __gnu_test::forward_iterator_wrapper; +using __gnu_test::input_iterator_wrapper; namespace ranges = std::ranges; namespace views = std::ranges::views; @@ -133,6 +134,24 @@ test07() static_assert( noexcept(iter_swap(b, b2)) ); } +void +test08() +{ + char x[] = "the quick brown fox"; + test_range rx(x, x+sizeof(x)-1); + auto v = rx | views::split(' '); + auto i = v.begin(); + VERIFY( ranges::equal(*i, "the"sv) ); + ++i; + VERIFY( ranges::equal(*i, "quick"sv) ); + ++i; + VERIFY( ranges::equal(*i, "brown"sv) ); + ++i; + VERIFY( ranges::equal(*i, "fox"sv) ); + ++i; + VERIFY( i == v.end() ); +} + int main() { @@ -143,4 +162,5 @@ main() test05(); test06(); test07(); + test08(); } diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index a915c02248b..5be47f47915 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -124,6 +124,11 @@ namespace __gnu_test struct output_iterator_wrapper : public std::iterator { + protected: + output_iterator_wrapper() : ptr(0), SharedInfo(0) + { } + + public: typedef OutputContainer ContainerType; T* ptr; ContainerType* SharedInfo; @@ -135,8 +140,6 @@ namespace __gnu_test } #if __cplusplus >= 201103L - output_iterator_wrapper() = delete; - output_iterator_wrapper(const output_iterator_wrapper&) = default; output_iterator_wrapper& @@ -706,13 +709,14 @@ namespace __gnu_test template class Iter> class test_range { - // Adds default constructor to Iter if needed + // Exposes the protected default constructor of Iter if needed. This + // is needed only when Iter is input_iterator_wrapper or + // output_iterator_wrapper, because legacy forward iterators and beyond + // are already default constructible. struct iterator : Iter { using Iter::Iter; - iterator() : Iter(nullptr, nullptr) { } - using Iter::operator++; iterator& operator++() { Iter::operator++(); return *this; }