From patchwork Thu Nov 9 21:12:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 836506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466452-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="w4cXyqlf"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yXwr30hhhz9t2R for ; Fri, 10 Nov 2017 08:13:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ono0jcQOZH8L8LTlfHxSrDGCIJKJNKtx5cs3/ePea348u9rXNd BrJr2546KQYd5W2bjHgi4o/HG+xSQhKYFU78hzWQ+8LlXDq905pgzLWSqfUBAzCd gkBG9z0SQfDo/v9PDddbebKcIib0e5LNJSVKdL5ZI6pL7aR7seG6NAgII= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=/ecDJw3sd71FI3pJQr1lfsw5hzw=; b=w4cXyqlfM+rori+KqH/p CHh1l5K6cbIXgt4CElJwyleoo5bFFOzLdJCKpJhMhPYrhvqbUR7Vj5mwaW7zM29a aDPhdh6lB1FhKH/gW1CzOUeACq8csTAqfRhQhYJAQtlSXqwda70eyYgKgM2Z8LGe X4rEOhIhb37QXqi0l61YZUU= Received: (qmail 63188 invoked by alias); 9 Nov 2017 21:13:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 63161 invoked by uid 89); 9 Nov 2017 21:13:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=1500, sgetc, 2.cc, basic_istream X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Nov 2017 21:12:57 +0000 Received: by mail-wm0-f54.google.com with SMTP id s66so19779100wmf.5; Thu, 09 Nov 2017 13:12:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=hkabBL0QteM5R5XbSaa7MS1DteFpN/6pymzuggTjDtw=; b=Xl13KvfHfADZ+627MI8UoqV4YcIgQFfljY7EDGhFoBkk8REozrWmHxyhIPmFadPdEk X2xn2sM9E3UvDzZoUFLwMV2yBkRpTCnEAejb74g0ls8DpGPnoFdfynTDW+UnDTaIDDBy 3S4RVlQXZAr+VnbLgbDkX9rxh4l0Xe88eF72OtMbNPg0yENyWEJEg5i9t1K5mp9KwFNb YPlfkq1yBdXBQNJA/ZgLvEIwol2SbTsKuYQRblTkETrO546l/jvK0IKtsaK95r0nVsml oaUff4Wce+Vj5Em0mNVBnF7PG9E9K8suTexfLB5CmpBc45L9CHPaai6mdWj+cMtLWmb1 YizA== X-Gm-Message-State: AJaThX7ScRs4L64dYjz5h4rK8VgEcIOXgHKKSdE0FaKtLrYxx89h25mW 4+qtTR1hVXslpsGttFKz42Gvcw== X-Google-Smtp-Source: ABhQp+Ro2LiMwsIAOCJ77K/mfV1L9GOnXRtg8Oa+edLbWCqO5MBqX9K3ZWwbGuR/xmeP9Z68DE3mJQ== X-Received: by 10.80.204.205 with SMTP id b13mr2419809edj.249.1510261974956; Thu, 09 Nov 2017 13:12:54 -0800 (PST) Received: from [192.168.0.23] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id h56sm8503908ede.15.2017.11.09.13.12.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 13:12:54 -0800 (PST) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: std::advance istreambuf_iterator overload Message-ID: Date: Thu, 9 Nov 2017 22:12:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Hi     Working on istreambuf_iterator I realized that this iterator would really benefit from an std::advance overload so here it is.     Tested under Linux x86_64 normal and debug modes, ok to commit ? François diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index 0a6c7f9..b60626a 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -86,6 +86,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, const _CharT2&); + template + friend void _GLIBCXX17_CONSTEXPR + advance(istreambuf_iterator<_CharT2>&, _Distance); + private: // 24.5.3 istreambuf_iterator // p 1 @@ -417,6 +421,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __last; } + template + inline _GLIBCXX17_CONSTEXPR void + advance(istreambuf_iterator<_CharT>& __i, _Distance __n) + { + if (__n == 0) + return; + + __glibcxx_assert(__n > 0); + __glibcxx_requires_cond(!__i._M_at_eof(), + _M_message(__gnu_debug::__msg_inc_istreambuf) + ._M_iterator(__i)); + + typedef istreambuf_iterator<_CharT> __is_iterator_type; + typedef typename __is_iterator_type::traits_type traits_type; + typedef typename __is_iterator_type::streambuf_type streambuf_type; + typedef typename traits_type::int_type int_type; + const int_type __eof = traits_type::eof(); + + streambuf_type* __sb = __i._M_sbuf; + int_type __c = __sb->sgetc(); + while (__n && !traits_type::eq_int_type(__c, __eof)) + { + streamsize __size = __sb->egptr() - __sb->gptr(); + if (__size > __n) + { + __sb->__safe_gbump(__n); + __n = 0; + } + else if (__size > 1) + { + __sb->__safe_gbump(__size); + __n -= __size; + __c = __sb->underflow(); + } + else + { + --__n; + __c = __sb->snextc(); + } + } + + __glibcxx_requires_cond(__n == 0, + _M_message(__gnu_debug::__msg_inc_istreambuf) + ._M_iterator(__i)); + __i._M_c = __eof; + if (traits_type::eq_int_type(__c, __eof)) + __i._M_sbuf = 0; + } + // @} group iterators _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf index a05b46e..da92199 100644 --- a/libstdc++-v3/include/std/streambuf +++ b/libstdc++-v3/include/std/streambuf @@ -159,6 +159,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, const _CharT2&); + template + friend _GLIBCXX17_CONSTEXPR void + advance(istreambuf_iterator<_CharT2>&, _Distance); + template friend basic_istream<_CharT2, _Traits2>& operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*); diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc new file mode 100644 index 0000000..7c3f882 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + istringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + + VERIFY( *beg1 == 'D' ); + + advance(beg1, 1); + + VERIFY( beg1 != end1 ); + VERIFY( *beg1 == 'r' ); + + advance(beg1, 0); + VERIFY( *beg1 == 'r' ); + + advance(beg1, 38); + VERIFY( *beg1 == 'n' ); + + advance(beg1, 1); + VERIFY( beg1 == end1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc new file mode 100644 index 0000000..d1b8cde --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + in_iterator_type end1; + + advance(end1, -1); // Invalid -1 value. +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc new file mode 100644 index 0000000..c99111e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include +#include + +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + unsigned found = 0; + + { + ifstream fbuf("istream_unformatted-1.txt"); + + in_iterator_type beg(fbuf); + in_iterator_type end; + + for (;;) + { + beg = find(beg, end, '1'); + if (beg == end) + break; + + ++found; + VERIFY( *beg == '1' ); + + advance(beg, 9); + VERIFY( *beg == '0' ); + } + } + + { + ifstream fbuf("istream_unformatted-1.txt"); + + in_iterator_type beg(fbuf); + in_iterator_type end; + + beg = find(beg, end, '1'); + VERIFY( beg != end ); + VERIFY( *beg == '1' ); + + advance(beg, 9); + VERIFY( *beg == '0' ); + + unsigned line_length = 10; + while (*++beg != '1') + ++line_length; + + // Try to jump directly to the end through advance. + advance(beg, (found - 2) * line_length + 9); + VERIFY( *beg == '0' ); + VERIFY( find(beg, end, '1') == end ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc new file mode 100644 index 0000000..9d18778 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2_neg.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + in_iterator_type end1; + + advance(end1, 0); // Ok. + + advance(end1, 1); // Invalid. +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc new file mode 100644 index 0000000..af2bed6 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/3_neg.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + istringstream iss1(str1); + in_iterator_type beg1(iss1); + + advance(beg1, 50); // Invalid +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc new file mode 100644 index 0000000..18839ca --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin"; + const wstring str1(data1); + wistringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + + VERIFY( *beg1 == L'D' ); + + advance(beg1, 1); + + VERIFY( beg1 != end1 ); + VERIFY( *beg1 == L'r' ); + + advance(beg1, 0); + VERIFY( *beg1 == L'r' ); + + advance(beg1, 38); + VERIFY( *beg1 == L'n' ); + + advance(beg1, 1); + VERIFY( beg1 == end1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc new file mode 100644 index 0000000..cd1b7a1 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/1_neg.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + in_iterator_type end1; + + advance(end1, -1); // Invalid -1 value. +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc new file mode 100644 index 0000000..91cc939 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include +#include + +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + unsigned found = 0; + + { + wifstream fbuf("istream_unformatted-1.txt"); + + in_iterator_type beg(fbuf); + in_iterator_type end; + + for (;;) + { + beg = find(beg, end, L'1'); + if (beg == end) + break; + + ++found; + VERIFY( *beg == L'1' ); + + advance(beg, 9); + VERIFY( *beg == L'0' ); + } + } + + { + wifstream fbuf("istream_unformatted-1.txt"); + + in_iterator_type beg(fbuf); + in_iterator_type end; + + beg = find(beg, end, L'1'); + VERIFY( beg != end ); + VERIFY( *beg == L'1' ); + + advance(beg, 9); + VERIFY( *beg == L'0' ); + + unsigned line_length = 10; + while (*++beg != L'1') + ++line_length; + + // Try to jump directly to the end through advance. + advance(beg, (found - 2) * line_length + 9); + VERIFY( *beg == L'0' ); + VERIFY( find(beg, end, L'1') == end ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc new file mode 100644 index 0000000..ea280f9 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2_neg.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + in_iterator_type end1; + + advance(end1, 0); // Ok. + + advance(end1, 1); // Invalid. +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc new file mode 100644 index 0000000..c5bf122 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/3_neg.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin"; + const wstring str1(data1); + wistringstream iss1(str1); + in_iterator_type beg1(iss1); + + advance(beg1, 50); // Invalid +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc index 125d597..b288787 100644 --- a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc +++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc @@ -46,8 +46,7 @@ void test01() ++found; VERIFY( *beg == '1' ); - for (unsigned sk = 0; sk < 9; sk++) - ++beg; + advance(beg, 9); VERIFY( *beg == '0' ); } VERIFY( found == 1500 ); diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc index e8d2b88..6393f49 100644 --- a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc +++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc @@ -44,8 +44,7 @@ void test01() ++found; VERIFY( *beg == L'1' ); - for (unsigned sk = 0; sk < 9; sk++) - ++beg; + advance(beg, 9); VERIFY( *beg == L'0' ); } VERIFY( found == 1500 );