From: Jonathan Wakely Date: Wed, 30 Oct 2019 15:48:11 +0000 (+0000) Subject: Apply C++20 changes to various iterator types X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9aeb3bef2cae234dbb90609392e536bafc09365c;p=gcc.git Apply C++20 changes to various iterator types This ensures that __normal_iterator satisfies the contiguous_iterator concept, by defining the iterator_concept member type. Also update vector's iterators, reverse_iterator, istreambuf_iterator and ostreambuf_iterator to meet the C++20 requirements. PR libstdc++/92272 * include/bits/stl_bvector.h (_Bit_iterator::pointer) (_Bit_const_iterator::pointer): Define as void for C++20. * include/bits/stl_iterator.h (reverse_iterator::operator->()): Add constraints for C++20. (__normal_iterator::iterator_concept): Define for C++20. * include/bits/streambuf_iterator.h (istreambuf_iterator::pointer): Define as void for C++20. (ostreambuf_iterator::difference_type): Define as ptrdiff_t for C++20. (ostreambuf_iterator::ostreambuf_iterator()): Add default constructor for C++20. * testsuite/23_containers/vector/bool/iterator_c++20.cc: New test. * testsuite/24_iterators/bidirectional/concept.cc: New test. * testsuite/24_iterators/bidirectional/tag.cc: New test. * testsuite/24_iterators/contiguous/concept.cc: New test. * testsuite/24_iterators/contiguous/tag.cc: New test. * testsuite/24_iterators/forward/concept.cc: New test. * testsuite/24_iterators/forward/tag.cc: New test. * testsuite/24_iterators/input/concept.cc: New test. * testsuite/24_iterators/input/tag.cc: New test. * testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc: New test. * testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc: New test. * testsuite/24_iterators/output/concept.cc: New test. * testsuite/24_iterators/output/tag.cc: New test. * testsuite/24_iterators/random_access/concept.cc: New test. * testsuite/24_iterators/random_access/tag.cc: New test. * testsuite/24_iterators/range_operations/advance_debug_neg.cc: New test. * testsuite/24_iterators/random_access_iterator/26020.cc: Move to ... * testsuite/24_iterators/operations/26020.cc: ... here. * testsuite/24_iterators/random_access_iterator/ string_vector_iterators.cc: Move to ... * testsuite/24_iterators/random_access/string_vector_iterators.cc: ... here. From-SVN: r277629 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ad736788106..12eca8f8138 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,42 @@ 2019-10-30 Jonathan Wakely + PR libstdc++/92272 + * include/bits/stl_bvector.h (_Bit_iterator::pointer) + (_Bit_const_iterator::pointer): Define as void for C++20. + * include/bits/stl_iterator.h (reverse_iterator::operator->()): Add + constraints for C++20. + (__normal_iterator::iterator_concept): Define for C++20. + * include/bits/streambuf_iterator.h (istreambuf_iterator::pointer): + Define as void for C++20. + (ostreambuf_iterator::difference_type): Define as ptrdiff_t for C++20. + (ostreambuf_iterator::ostreambuf_iterator()): Add default constructor + for C++20. + * testsuite/23_containers/vector/bool/iterator_c++20.cc: New test. + * testsuite/24_iterators/bidirectional/concept.cc: New test. + * testsuite/24_iterators/bidirectional/tag.cc: New test. + * testsuite/24_iterators/contiguous/concept.cc: New test. + * testsuite/24_iterators/contiguous/tag.cc: New test. + * testsuite/24_iterators/forward/concept.cc: New test. + * testsuite/24_iterators/forward/tag.cc: New test. + * testsuite/24_iterators/input/concept.cc: New test. + * testsuite/24_iterators/input/tag.cc: New test. + * testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc: + New test. + * testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc: + New test. + * testsuite/24_iterators/output/concept.cc: New test. + * testsuite/24_iterators/output/tag.cc: New test. + * testsuite/24_iterators/random_access/concept.cc: New test. + * testsuite/24_iterators/random_access/tag.cc: New test. + * testsuite/24_iterators/range_operations/advance_debug_neg.cc: New + test. + * testsuite/24_iterators/random_access_iterator/26020.cc: Move to ... + * testsuite/24_iterators/operations/26020.cc: ... here. + * testsuite/24_iterators/random_access_iterator/ + string_vector_iterators.cc: Move to ... + * testsuite/24_iterators/random_access/string_vector_iterators.cc: ... + here. + * testsuite/util/testsuite_iterators.h: Fix typo in __cplusplus check. 2019-10-29 Jonathan Wakely diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 280d40f60c5..f2eea7799dc 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -220,7 +220,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER struct _Bit_iterator : public _Bit_iterator_base { typedef _Bit_reference reference; +#if __cplusplus > 201703L + typedef void pointer; +#else typedef _Bit_reference* pointer; +#endif typedef _Bit_iterator iterator; _Bit_iterator() : _Bit_iterator_base(0, 0) { } @@ -309,7 +313,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { typedef bool reference; typedef bool const_reference; +#if __cplusplus > 201703L + typedef void pointer; +#else typedef const bool* pointer; +#endif typedef _Bit_const_iterator const_iterator; _Bit_const_iterator() : _Bit_iterator_base(0, 0) { } diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index c10117e9b38..2a3b0231079 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -187,6 +187,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ _GLIBCXX17_CONSTEXPR pointer operator->() const +#if __cplusplus > 201703L && defined __cpp_concepts + requires is_pointer_v<_Iterator> + || requires(const _Iterator __i) { __i.operator->(); } +#endif { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 1052. operator-> should also support smart pointers @@ -807,6 +811,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename __traits_type::reference reference; typedef typename __traits_type::pointer pointer; +#if __cplusplus > 201703L + using iterator_concept = std::__detail::__iter_concept<_Iterator>; +#endif + _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT : _M_current(_Iterator()) { } diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index e3e8736e768..077b11a5ff5 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -61,6 +61,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Types: //@{ /// Public typedefs +#if __cplusplus > 201703L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3188. istreambuf_iterator::pointer should not be unspecified + using pointer = void; +#endif typedef _CharT char_type; typedef _Traits traits_type; typedef typename _Traits::int_type int_type; @@ -230,6 +235,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Types: //@{ /// Public typedefs +#if __cplusplus > 201703L + using difference_type = ptrdiff_t; +#endif typedef _CharT char_type; typedef _Traits traits_type; typedef basic_streambuf<_CharT, _Traits> streambuf_type; @@ -247,6 +255,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_failed; public: + +#if __cplusplus > 201703L + constexpr + ostreambuf_iterator() noexcept + : _M_sbuf(nullptr), _M_failed(true) { } +#endif + /// Construct output iterator from ostream. ostreambuf_iterator(ostream_type& __s) _GLIBCXX_USE_NOEXCEPT : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { } diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/iterator_c++20.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/iterator_c++20.cc new file mode 100644 index 00000000000..2a36d98672b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/iterator_c++20.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +// C++20 [iterator.traits]: The type iterator_traits::pointer shall be void +// for an iterator of class type I that does not support operator->. +template + concept arrow_or_no_pointer = requires (I i) { i.operator->(); } + || std::same_as::pointer, void>; + +static_assert( arrow_or_no_pointer::iterator> ); +static_assert( arrow_or_no_pointer::const_iterator> ); diff --git a/libstdc++-v3/testsuite/24_iterators/bidirectional/concept.cc b/libstdc++-v3/testsuite/24_iterators/bidirectional/concept.cc new file mode 100644 index 00000000000..0bcd6f52c5b --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/bidirectional/concept.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +using std::bidirectional_iterator; + +static_assert( bidirectional_iterator< int* > ); +static_assert( bidirectional_iterator< const int* > ); +static_assert( bidirectional_iterator< void** > ); + +static_assert( ! bidirectional_iterator< int* const > ); +static_assert( ! bidirectional_iterator< const int* const > ); +static_assert( ! bidirectional_iterator< void** const > ); + +static_assert( ! bidirectional_iterator< void* > ); +static_assert( ! bidirectional_iterator< const void* > ); +static_assert( ! bidirectional_iterator< volatile void* > ); + +static_assert( ! bidirectional_iterator< void(*)() > ); +static_assert( ! bidirectional_iterator< void(&)() > ); + +struct A; +static_assert( ! bidirectional_iterator< void(A::*)() > ); +static_assert( ! bidirectional_iterator< int A::* > ); + +#include +#include +#include +#include +#include +#include +#include + +using std::array; +using std::deque; +using std::forward_list; +using std::list; +using std::string; +using std::string_view; +using std::vector; + +struct B { }; + +static_assert( bidirectional_iterator< array::iterator > ); +static_assert( bidirectional_iterator< array::const_iterator > ); + +static_assert( bidirectional_iterator< deque::iterator > ); +static_assert( bidirectional_iterator< deque::const_iterator > ); + +static_assert( bidirectional_iterator< list::iterator > ); +static_assert( bidirectional_iterator< list::const_iterator > ); + +static_assert( ! bidirectional_iterator< forward_list::iterator > ); +static_assert( ! bidirectional_iterator< forward_list::const_iterator > ); + +static_assert( bidirectional_iterator< string::iterator > ); +static_assert( bidirectional_iterator< string::const_iterator > ); + +static_assert( bidirectional_iterator< string_view::iterator > ); +static_assert( bidirectional_iterator< string_view::const_iterator > ); + +static_assert( bidirectional_iterator< vector::iterator > ); +static_assert( bidirectional_iterator< vector::const_iterator > ); diff --git a/libstdc++-v3/testsuite/24_iterators/bidirectional/tag.cc b/libstdc++-v3/testsuite/24_iterators/bidirectional/tag.cc new file mode 100644 index 00000000000..9b24b3102e6 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/bidirectional/tag.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2019 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 compile { target c++11 } } + +#include + +using std::bidirectional_iterator_tag; +using std::forward_iterator_tag; +using std::iterator_traits; + +static_assert( std::is_empty::value ); +static_assert( std::is_trivially_copy_constructible::value ); + +static_assert( std::is_base_of::value ); +static_assert( std::is_convertible::value ); diff --git a/libstdc++-v3/testsuite/24_iterators/contiguous/concept.cc b/libstdc++-v3/testsuite/24_iterators/contiguous/concept.cc index a9bb42e023f..0f9419aaba1 100644 --- a/libstdc++-v3/testsuite/24_iterators/contiguous/concept.cc +++ b/libstdc++-v3/testsuite/24_iterators/contiguous/concept.cc @@ -20,17 +20,61 @@ #include -static_assert( std::contiguous_iterator ); -static_assert( std::contiguous_iterator ); -static_assert( std::contiguous_iterator ); +using std::contiguous_iterator; -static_assert( ! std::contiguous_iterator ); -static_assert( ! std::contiguous_iterator ); -static_assert( ! std::contiguous_iterator ); +static_assert( contiguous_iterator< int* > ); +static_assert( contiguous_iterator< const int* > ); +static_assert( contiguous_iterator< void** > ); -static_assert( ! std::contiguous_iterator ); -static_assert( ! std::contiguous_iterator ); +static_assert( ! contiguous_iterator< int* const > ); +static_assert( ! contiguous_iterator< const int* const > ); +static_assert( ! contiguous_iterator< void** const > ); + +static_assert( ! contiguous_iterator< void* > ); +static_assert( ! contiguous_iterator< const void* > ); +static_assert( ! contiguous_iterator< volatile void* > ); + +static_assert( ! contiguous_iterator< void(*)() > ); +static_assert( ! contiguous_iterator< void(&)() > ); +static_assert( contiguous_iterator< void(**)() > ); struct A; -static_assert( ! std::contiguous_iterator ); -static_assert( ! std::contiguous_iterator ); +static_assert( ! contiguous_iterator< void(A::*)() > ); +static_assert( ! contiguous_iterator< int A::* > ); + +#include +#include +#include +#include +#include +#include + +using std::array; +using std::deque; +using std::list; +using std::string; +using std::string_view; +using std::vector; + +struct B { }; + +static_assert( contiguous_iterator< array::iterator > ); +static_assert( contiguous_iterator< array::const_iterator > ); + +static_assert( ! contiguous_iterator< deque::iterator > ); +static_assert( ! contiguous_iterator< deque::const_iterator > ); + +static_assert( ! contiguous_iterator< list::iterator > ); +static_assert( ! contiguous_iterator< list::const_iterator > ); + +static_assert( contiguous_iterator< string::iterator > ); +static_assert( contiguous_iterator< string::const_iterator > ); + +static_assert( contiguous_iterator< string_view::iterator > ); +static_assert( contiguous_iterator< string_view::const_iterator > ); + +static_assert( contiguous_iterator< vector::iterator > ); +static_assert( contiguous_iterator< vector::const_iterator > ); + +static_assert( ! contiguous_iterator< vector::iterator > ); +static_assert( ! contiguous_iterator< vector::const_iterator > ); diff --git a/libstdc++-v3/testsuite/24_iterators/contiguous/tag.cc b/libstdc++-v3/testsuite/24_iterators/contiguous/tag.cc index 7673131f215..8a0029c338b 100644 --- a/libstdc++-v3/testsuite/24_iterators/contiguous/tag.cc +++ b/libstdc++-v3/testsuite/24_iterators/contiguous/tag.cc @@ -20,6 +20,10 @@ #include +using std::contiguous_iterator_tag; +using std::random_access_iterator_tag; +using std::iterator_traits; + static_assert( std::is_empty_v ); static_assert( std::is_trivially_copy_constructible_v ); diff --git a/libstdc++-v3/testsuite/24_iterators/forward/concept.cc b/libstdc++-v3/testsuite/24_iterators/forward/concept.cc new file mode 100644 index 00000000000..4b125e52fda --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/forward/concept.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +using std::forward_iterator; + +static_assert( forward_iterator< int* > ); +static_assert( forward_iterator< const int* > ); +static_assert( forward_iterator< void** > ); + +static_assert( ! forward_iterator< int* const > ); +static_assert( ! forward_iterator< const int* const > ); +static_assert( ! forward_iterator< void** const > ); + +static_assert( ! forward_iterator< void* > ); +static_assert( ! forward_iterator< const void* > ); +static_assert( ! forward_iterator< volatile void* > ); + +static_assert( ! forward_iterator< void(*)() > ); +static_assert( ! forward_iterator< void(&)() > ); + +struct A; +static_assert( ! forward_iterator< void(A::*)() > ); +static_assert( ! forward_iterator< int A::* > ); + +#include +#include +#include +#include +#include +#include +#include + +using std::array; +using std::deque; +using std::forward_list; +using std::list; +using std::string; +using std::string_view; +using std::vector; +using std::istreambuf_iterator; +using std::ostreambuf_iterator; + +struct B { }; + +static_assert( forward_iterator< array::iterator > ); +static_assert( forward_iterator< array::const_iterator > ); + +static_assert( forward_iterator< deque::iterator > ); +static_assert( forward_iterator< deque::const_iterator > ); + +static_assert( forward_iterator< forward_list::iterator > ); +static_assert( forward_iterator< forward_list::const_iterator > ); + +static_assert( forward_iterator< list::iterator > ); +static_assert( forward_iterator< list::const_iterator > ); + +static_assert( forward_iterator< string::iterator > ); +static_assert( forward_iterator< string::const_iterator > ); + +static_assert( forward_iterator< string_view::iterator > ); +static_assert( forward_iterator< string_view::const_iterator > ); + +static_assert( forward_iterator< vector::iterator > ); +static_assert( forward_iterator< vector::const_iterator > ); + +static_assert( ! forward_iterator< istreambuf_iterator > ); +static_assert( ! forward_iterator< ostreambuf_iterator > ); diff --git a/libstdc++-v3/testsuite/24_iterators/forward/tag.cc b/libstdc++-v3/testsuite/24_iterators/forward/tag.cc new file mode 100644 index 00000000000..6ec325606fe --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/forward/tag.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2019 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 compile { target c++11 } } + +#include + +using std::forward_iterator_tag; +using std::input_iterator_tag; +using std::iterator_traits; + +static_assert( std::is_empty::value ); +static_assert( std::is_trivially_copy_constructible::value ); + +static_assert( std::is_base_of::value ); +static_assert( std::is_convertible::value ); diff --git a/libstdc++-v3/testsuite/24_iterators/input/concept.cc b/libstdc++-v3/testsuite/24_iterators/input/concept.cc new file mode 100644 index 00000000000..80bb679a7c0 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/input/concept.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +using std::input_iterator; + +static_assert( input_iterator< int* > ); +static_assert( input_iterator< const int* > ); +static_assert( input_iterator< void** > ); + +static_assert( ! input_iterator< int* const > ); +static_assert( ! input_iterator< const int* const > ); +static_assert( ! input_iterator< void** const > ); + +static_assert( ! input_iterator< void* > ); +static_assert( ! input_iterator< const void* > ); +static_assert( ! input_iterator< volatile void* > ); + +static_assert( ! input_iterator< void(*)() > ); +static_assert( ! input_iterator< void(&)() > ); + +struct A; +static_assert( ! input_iterator< void(A::*)() > ); +static_assert( ! input_iterator< int A::* > ); + +#include +#include +#include +#include +#include +#include +#include + +using std::array; +using std::deque; +using std::forward_list; +using std::list; +using std::string; +using std::string_view; +using std::vector; + +struct B { }; + +static_assert( input_iterator< array::iterator > ); +static_assert( input_iterator< array::const_iterator > ); + +static_assert( input_iterator< deque::iterator > ); +static_assert( input_iterator< deque::const_iterator > ); + +static_assert( input_iterator< forward_list::iterator > ); +static_assert( input_iterator< forward_list::const_iterator > ); + +static_assert( input_iterator< list::iterator > ); +static_assert( input_iterator< list::const_iterator > ); + +static_assert( input_iterator< string::iterator > ); +static_assert( input_iterator< string::const_iterator > ); + +static_assert( input_iterator< string_view::iterator > ); +static_assert( input_iterator< string_view::const_iterator > ); + +static_assert( input_iterator< vector::iterator > ); +static_assert( input_iterator< vector::const_iterator > ); + +#include + +using std::istreambuf_iterator; +using std::ostreambuf_iterator; + +static_assert( input_iterator< istreambuf_iterator > ); +static_assert( ! input_iterator< ostreambuf_iterator > ); diff --git a/libstdc++-v3/testsuite/24_iterators/input/tag.cc b/libstdc++-v3/testsuite/24_iterators/input/tag.cc new file mode 100644 index 00000000000..ade01c40db8 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/input/tag.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2019 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 compile { target c++11 } } + +#include + +using std::input_iterator_tag; +using std::output_iterator_tag; +using std::iterator_traits; + +static_assert( std::is_empty::value ); +static_assert( std::is_trivially_copy_constructible::value ); + +static_assert( ! std::is_base_of::value ); +static_assert( ! std::is_convertible::value ); diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc index 59a99a52213..fcd703e5928 100644 --- a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc +++ b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc @@ -22,7 +22,6 @@ #include #include -#include void test01() { @@ -41,3 +40,53 @@ void test01() typedef test_iterator::istream_type istream_type; typedef test_iterator::streambuf_type streambuf_type; } + +#if __cplusplus >= 201103L +void test02() +{ + using namespace std; + + using test_type = istreambuf_iterator; + + static_assert(is_same::value, ""); + static_assert(is_same::off_type>::value, ""); +#if __cplusplus <= 201703L + static_assert(is_same::value, ""); +#else + static_assert(is_same::value, ""); +#endif + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + + static_assert(is_same::value, ""); + static_assert(is_same>::value, ""); + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); +} + +#ifdef _GLIBCXX_USE_WCHAR_T +void test03() +{ + using namespace std; + + using test_type = istreambuf_iterator; + + static_assert(is_same::value, ""); + static_assert(is_same::off_type>::value, ""); +#if __cplusplus <= 201703L + static_assert(is_same::value, ""); +#else + static_assert(is_same::value, ""); +#endif + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + + static_assert(is_same::value, ""); + static_assert(is_same>::value, ""); + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); +} +#endif +#endif diff --git a/libstdc++-v3/testsuite/24_iterators/operations/26020.cc b/libstdc++-v3/testsuite/24_iterators/operations/26020.cc new file mode 100644 index 00000000000..ec2344374d9 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/operations/26020.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2006-2019 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 +// . + +// 24.3.4 Iterator operations + +#include +#include +#include + +//libstdc++/26020 +void test01() +{ + using namespace std; + + list ll; + ll.push_back(1); + + list::iterator it(ll.begin()); + + advance(it, 0.5); + + VERIFY( it == ll.begin() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc index 51292b9d783..11813e39174 100644 --- a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc +++ b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc @@ -41,3 +41,49 @@ void test01() typedef test_iterator::ostream_type ostream_type; typedef test_iterator::streambuf_type streambuf_type; } + +#if __cplusplus >= 201103L +void test02() +{ + using namespace std; + + using test_type = ostreambuf_iterator; + static_assert(is_same::value, ""); +#if __cplusplus <= 201703L + static_assert(is_same::value, ""); +#else + static_assert(is_same::value, ""); +#endif + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + + static_assert(is_same::value, ""); + static_assert(is_same>::value, ""); + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); +} + +#ifdef _GLIBCXX_USE_WCHAR_T +void test03() +{ + using namespace std; + + using test_type = ostreambuf_iterator; + static_assert(is_same::value, ""); +#if __cplusplus <= 201703L + static_assert(is_same::value, ""); +#else + static_assert(is_same::value, ""); +#endif + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + + static_assert(is_same::value, ""); + static_assert(is_same>::value, ""); + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); +} +#endif +#endif diff --git a/libstdc++-v3/testsuite/24_iterators/output/concept.cc b/libstdc++-v3/testsuite/24_iterators/output/concept.cc new file mode 100644 index 00000000000..1b8c593d844 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/output/concept.cc @@ -0,0 +1,121 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +using std::output_iterator; + +static_assert( output_iterator< int*, int > ); +static_assert( output_iterator< int*, const int > ); +static_assert( output_iterator< int*, long > ); +static_assert( output_iterator< void**, void* > ); +static_assert( output_iterator< void**, long* > ); +static_assert( ! output_iterator< const int*, int > ); + +static_assert( ! output_iterator< int* const, int > ); +static_assert( ! output_iterator< const int* const, int > ); +static_assert( ! output_iterator< void** const, void* > ); + +static_assert( ! output_iterator< void*, void > ); +static_assert( ! output_iterator< const void*, void > ); +static_assert( ! output_iterator< const void*, void* > ); +static_assert( ! output_iterator< volatile void*, void > ); +static_assert( ! output_iterator< volatile void*, void* > ); + +static_assert( ! output_iterator< void(*)(), void(&)() > ); +static_assert( ! output_iterator< void(&)(), void(&)() > ); +static_assert( output_iterator< void(**)(), void(*)() > ); +static_assert( output_iterator< void(**)(), void(&)() > ); + +struct A; +static_assert( ! output_iterator< void(A::*)(), A* > ); +static_assert( ! output_iterator< void(A::*)(), void(A::*)() > ); +static_assert( ! output_iterator< int A::*, int > ); +static_assert( ! output_iterator< int A::*, int A::* > ); + +#include +#include +#include +#include +#include +#include +#include +#include + +using std::array; +using std::deque; +using std::forward_list; +using std::list; +using std::set; +using std::string; +using std::string_view; +using std::vector; + +struct B { }; + +static_assert( output_iterator< array::iterator, int > ); +static_assert( output_iterator< array::iterator, B > ); +static_assert( ! output_iterator< array::const_iterator, int > ); +static_assert( ! output_iterator< array::const_iterator, B > ); + +static_assert( output_iterator< deque::iterator, int > ); +static_assert( output_iterator< deque::iterator, B > ); +static_assert( ! output_iterator< deque::const_iterator, int > ); +static_assert( ! output_iterator< deque::const_iterator, B > ); + +static_assert( output_iterator< forward_list::iterator, int > ); +static_assert( output_iterator< forward_list::iterator, B > ); +static_assert( ! output_iterator< forward_list::const_iterator, int > ); +static_assert( ! output_iterator< forward_list::const_iterator, B > ); + +static_assert( output_iterator< list::iterator, int > ); +static_assert( output_iterator< list::iterator, B > ); +static_assert( ! output_iterator< list::const_iterator, int > ); +static_assert( ! output_iterator< list::const_iterator, B > ); + +static_assert( ! output_iterator< set::iterator, int > ); +static_assert( ! output_iterator< set::iterator, B > ); +static_assert( ! output_iterator< set::const_iterator, int > ); +static_assert( ! output_iterator< set::const_iterator, B > ); + +static_assert( output_iterator< string::iterator, char > ); +static_assert( output_iterator< string::iterator, int > ); +static_assert( ! output_iterator< string::const_iterator, char > ); +static_assert( ! output_iterator< string::const_iterator, int > ); + +static_assert( ! output_iterator< string_view::iterator, char > ); +static_assert( ! output_iterator< string_view::iterator, int > ); +static_assert( ! output_iterator< string_view::const_iterator, char > ); +static_assert( ! output_iterator< string_view::const_iterator, int > ); + +static_assert( output_iterator< vector::iterator, int > ); +static_assert( output_iterator< vector::iterator, B > ); +static_assert( ! output_iterator< vector::const_iterator, int > ); +static_assert( ! output_iterator< vector::const_iterator, B > ); + +#include + +using std::istreambuf_iterator; +using std::ostreambuf_iterator; + +static_assert( ! output_iterator< istreambuf_iterator, char > ); +static_assert( ! output_iterator< istreambuf_iterator, int > ); +static_assert( output_iterator< ostreambuf_iterator, char > ); +static_assert( output_iterator< ostreambuf_iterator, int > ); diff --git a/libstdc++-v3/testsuite/24_iterators/output/tag.cc b/libstdc++-v3/testsuite/24_iterators/output/tag.cc new file mode 100644 index 00000000000..515088eb1c0 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/output/tag.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2019 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 compile { target c++11 } } + +#include + +using std::output_iterator_tag; +using std::input_iterator_tag; +using std::iterator_traits; + +static_assert( std::is_empty::value ); +static_assert( std::is_trivially_copy_constructible::value ); + +static_assert( ! std::is_base_of::value ); +static_assert( ! std::is_convertible::value ); diff --git a/libstdc++-v3/testsuite/24_iterators/random_access/concept.cc b/libstdc++-v3/testsuite/24_iterators/random_access/concept.cc new file mode 100644 index 00000000000..f513c57fe36 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/random_access/concept.cc @@ -0,0 +1,76 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +using std::random_access_iterator; + +static_assert( random_access_iterator< int* > ); +static_assert( random_access_iterator< const int* > ); +static_assert( random_access_iterator< void** > ); + +static_assert( ! random_access_iterator< int* const > ); +static_assert( ! random_access_iterator< const int* const > ); +static_assert( ! random_access_iterator< void** const > ); + +static_assert( ! random_access_iterator< void* > ); +static_assert( ! random_access_iterator< const void* > ); +static_assert( ! random_access_iterator< volatile void* > ); + +static_assert( ! random_access_iterator< void(*)() > ); +static_assert( ! random_access_iterator< void(&)() > ); + +struct A; +static_assert( ! random_access_iterator< void(A::*)() > ); +static_assert( ! random_access_iterator< int A::* > ); + +#include +#include +#include +#include +#include +#include + +using std::array; +using std::deque; +using std::list; +using std::string; +using std::string_view; +using std::vector; + +struct B { }; + +static_assert( random_access_iterator< array::iterator > ); +static_assert( random_access_iterator< array::const_iterator > ); + +static_assert( random_access_iterator< deque::iterator > ); +static_assert( random_access_iterator< deque::const_iterator > ); + +static_assert( ! random_access_iterator< list::iterator > ); +static_assert( ! random_access_iterator< list::const_iterator > ); + +static_assert( random_access_iterator< string::iterator > ); +static_assert( random_access_iterator< string::const_iterator > ); + +static_assert( random_access_iterator< string_view::iterator > ); +static_assert( random_access_iterator< string_view::const_iterator > ); + +static_assert( random_access_iterator< vector::iterator > ); +static_assert( random_access_iterator< vector::const_iterator > ); diff --git a/libstdc++-v3/testsuite/24_iterators/random_access/string_vector_iterators.cc b/libstdc++-v3/testsuite/24_iterators/random_access/string_vector_iterators.cc new file mode 100644 index 00000000000..c496254a228 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/random_access/string_vector_iterators.cc @@ -0,0 +1,607 @@ +// 24.1.5 Random access iterators +// 24.3.1 Iterator traits +// (basic_string and vector implementations) +// +// Copyright (C) 1999-2019 Free Software Foundation, Inc. +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program; see the file COPYING3. If not see +// . + + +#include +#include +#include + +int +string_stuff() +{ + int failures(0); + + std::string s("abcde"); + + std::string::iterator i1(s.begin()); + if (*i1 != 'a') + ++failures; + + ++i1; + if (*i1 != 'b') + ++failures; + + if (*i1++ != 'b') + ++failures; + if (*i1 != 'c') + ++failures; + + ++ ++i1; + if (*i1 != 'e') + ++failures; + + --i1; + if (*i1 != 'd') + ++failures; + + if (*i1-- != 'd') + ++failures; + if (*i1 != 'c') + ++failures; + + -- --i1; + if (*i1 != 'a') + ++failures; + + std::string::iterator i2; + i2 = s.end(); + std::iterator_traits::difference_type d1; + d1 = i2 - i1; + if (d1 != 5) + ++failures; + + std::iterator_traits::value_type v1; + v1 = i1[0]; + if (v1 != 'a') + ++failures; + + std::iterator_traits::reference r1(i1[0]); + if (r1 != 'a') + ++failures; + r1 = 'x'; + if (r1 != 'x') + ++failures; + r1 = 'a'; + + if ((i1 != i2) != true) + ++failures; + if ((i1 == i2) != false) + ++failures; + if ((i1 < i2) != true) + ++failures; + if ((i1 > i2) != false) + ++failures; + if ((i1 <= i2) != true) + ++failures; + if ((i1 >= i2) != false) + ++failures; + + std::string::iterator i3; + i3 = i1; + if ((i3 == i1) != true) + ++failures; + + i3 += 5; + if ((i3 == i2) != true) + ++failures; + + i3 -= 5; + if ((i3 == i1) != true) + ++failures; + + if (i3 + 5 != i2) + ++failures; + + if (5 + i3 != i2) + ++failures; + + if (i2 - 5 != i3) + ++failures; + + if (i1[0] != 'a') + ++failures; + + i1[4] = 'x'; + if (i2[-1] != 'x') + ++failures; + i1[4] = 'e'; + + i1[2] = 'x'; + if (i2[-3] != 'x') + ++failures; + i1[2] = 'c'; + + std::string::const_iterator ci1(s.begin()); + if (*ci1 != 'a') + ++failures; + + ++ci1; + if (*ci1 != 'b') + ++failures; + + if (*ci1++ != 'b') + ++failures; + if (*ci1 != 'c') + ++failures; + + ++ ++ci1; + if (*ci1 != 'e') + ++failures; + + --ci1; + if (*ci1 != 'd') + ++failures; + + if (*ci1-- != 'd') + ++failures; + if (*ci1 != 'c') + ++failures; + + -- --ci1; + if (*ci1 != 'a') + ++failures; + + std::string::const_iterator ci2; + ci2 = s.end(); + std::iterator_traits::difference_type d2; + d2 = ci2 - ci1; + if (d2 != 5) + ++failures; + + std::iterator_traits::value_type v2; + v2 = ci1[0]; + if (v2 != 'a') + ++failures; + + std::iterator_traits::reference r2(ci1[0]); + if (r2 != 'a') + ++failures; + + if ((ci1 != ci2) != true) + ++failures; + if ((ci1 == ci2) != false) + ++failures; + if ((ci1 < ci2) != true) + ++failures; + if ((ci1 > ci2) != false) + ++failures; + if ((ci1 <= ci2) != true) + ++failures; + if ((ci1 >= ci2) != false) + ++failures; + + std::string::const_iterator ci3; + ci3 = ci1; + if ((ci3 == ci1) != true) + ++failures; + + ci3 += 5; + if ((ci3 == ci2) != true) + ++failures; + + ci3 -= 5; + if ((ci3 == ci1) != true) + ++failures; + + if (ci3 + 5 != ci2) + ++failures; + + if (5 + ci3 != ci2) + ++failures; + + if (ci2 - 5 != ci3) + ++failures; + + if (ci1[2] != 'c') + ++failures; + + if (ci2[-1] != 'e') + ++failures; + + // iterator and const_iterator + std::string::const_iterator ci4(i1); + if ((ci4 == i1) != true) + ++failures; + if ((ci4 != i1) != false) + ++failures; + if ((ci4 < i1) != false) + ++failures; + if ((ci4 > i1) != false) + ++failures; + if ((ci4 <= i1) != true) + ++failures; + if ((ci4 >= i1) != true) + ++failures; + ci4 = i2; + if ((i2 == ci4) != true) + ++failures; + if ((i2 < ci4) != false) + ++failures; + if ((i2 > ci4) != false) + ++failures; + if ((i2 <= ci4) != true) + ++failures; + if ((i2 >= ci4) != true) + ++failures; + + const std::string cs("ABCDE"); + std::string::const_iterator ci5(cs.begin()); + if (ci5[0] != 'A') + ++failures; + + return failures; +} + +int +vector_stuff() +{ + int failures(0); + + std::vector v; + v.push_back(int(1)); + v.push_back(int(2)); + v.push_back(int(3)); + v.push_back(int(4)); + v.push_back(int(5)); + + std::vector::iterator i1(v.begin()); + if (*i1 != 1) + ++failures; + + ++i1; + if (*i1 != 2) + ++failures; + + if (*i1++ != 2) + ++failures; + if (*i1 != 3) + ++failures; + + ++ ++i1; + if (*i1 != 5) + ++failures; + + --i1; + if (*i1 != 4) + ++failures; + + if (*i1-- != 4) + ++failures; + if (*i1 != 3) + ++failures; + + -- --i1; + if (*i1 != 1) + ++failures; + + std::vector::iterator i2; + i2 = v.end(); + std::iterator_traits::iterator>::difference_type d1; + d1 = i2 - i1; + if (d1 != 5) + ++failures; + + std::iterator_traits::iterator>::value_type v1; + v1 = i1[0]; + if (v1 != 1) + ++failures; + + std::iterator_traits::iterator>::reference r1(i1[0]); + if (r1 != 1) + ++failures; + r1 = 9; + if (r1 != 9) + ++failures; + r1 = 1; + + if ((i1 != i2) != true) + ++failures; + if ((i1 == i2) != false) + ++failures; + if ((i1 < i2) != true) + ++failures; + if ((i1 > i2) != false) + ++failures; + if ((i1 <= i2) != true) + ++failures; + if ((i1 >= i2) != false) + ++failures; + + std::vector::iterator i3; + i3 = i1; + if ((i3 == i1) != true) + ++failures; + + i3 += 5; + if ((i3 == i2) != true) + ++failures; + + i3 -= 5; + if ((i3 == i1) != true) + ++failures; + + if (i3 + 5 != i2) + ++failures; + + if (5 + i3 != i2) + ++failures; + + if (i2 - 5 != i3) + ++failures; + + if (i1[0] != 1) + ++failures; + + i1[4] = 9; + if (i2[-1] != 9) + ++failures; + i1[4] = 5; + + i1[2] = 9; + if (i2[-3] != 9) + ++failures; + i1[2] = 3; + + std::vector::const_iterator ci1(v.begin()); + if (*ci1 != 1) + ++failures; + + ++ci1; + if (*ci1 != 2) + ++failures; + + if (*ci1++ != 2) + ++failures; + if (*ci1 != 3) + ++failures; + + ++ ++ci1; + if (*ci1 != 5) + ++failures; + + --ci1; + if (*ci1 != 4) + ++failures; + + if (*ci1-- != 4) + ++failures; + if (*ci1 != 3) + ++failures; + + -- --ci1; + if (*ci1 != 1) + ++failures; + + std::vector::const_iterator ci2; + ci2 = v.end(); + std::iterator_traits::const_iterator>::difference_type d2; + d2 = ci2 - ci1; + if (d2 != 5) + ++failures; + + std::iterator_traits::const_iterator>::value_type v2; + v2 = ci1[0]; + if (v2 != 1) + ++failures; + + std::iterator_traits::const_iterator>::reference + r2(ci1[0]); + if (r2 != 1) + ++failures; + + if ((ci1 != ci2) != true) + ++failures; + if ((ci1 == ci2) != false) + ++failures; + if ((ci1 < ci2) != true) + ++failures; + if ((ci1 > ci2) != false) + ++failures; + if ((ci1 <= ci2) != true) + ++failures; + if ((ci1 >= ci2) != false) + ++failures; + + std::vector::const_iterator ci3; + ci3 = ci1; + if ((ci3 == ci1) != true) + ++failures; + + ci3 += 5; + if ((ci3 == ci2) != true) + ++failures; + + ci3 -= 5; + if ((ci3 == ci1) != true) + ++failures; + + if (ci3 + 5 != ci2) + ++failures; + + if (5 + ci3 != ci2) + ++failures; + + if (ci2 - 5 != ci3) + ++failures; + + if (ci1[2] != 3) + ++failures; + + if (ci2[-1] != 5) + ++failures; + + // iterator to const_iterator + std::vector::const_iterator ci4(i1); + if ((ci4 == i1) != true) + ++failures; + if ((ci4 != i1) != false) + ++failures; + if ((ci4 < i1) != false) + ++failures; + if ((ci4 > i1) != false) + ++failures; + if ((ci4 <= i1) != true) + ++failures; + if ((ci4 >= i1) != true) + ++failures; + ci4 = i2; + if ((i2 == ci4) != true) + ++failures; + if ((i2 < ci4) != false) + ++failures; + if ((i2 > ci4) != false) + ++failures; + if ((i2 <= ci4) != true) + ++failures; + if ((i2 >= ci4) != true) + ++failures; + + const std::vector cv(v); + std::vector::const_iterator ci5(cv.begin()); + if (ci5[0] != 1) + ++failures; + + std::vector vs; + vs.push_back(std::string("abc")); + std::vector::iterator ivs(vs.begin()); + if (ivs->c_str()[1] != 'b') + ++failures; + + return failures; +} + +int +reverse_stuff() +{ + int failures(0); + + std::string s("abcde"); + + std::string::reverse_iterator ri(s.rbegin()); + if (*ri != 'e') + ++failures; + + std::iterator_traits::difference_type d; + d = s.rend() - ri; + if (d != 5) + ++failures; + + const std::string cs("abcde"); + std::string::const_reverse_iterator cri(cs.rend()); + if (cri - 5 != cs.rbegin()) + ++failures; + + return failures; +} + +// the following should be compiler errors +// flag runtime errors in case they slip through the compiler +int +wrong_stuff() +{ + int failures(0); + +#ifdef ITER24_F1 + extern void f(std::vector::iterator); + std::vector vs[2]; + f(vs); // address of array is not an iterator + failures++; +#endif + +#ifdef ITER24_F2 + std::string s; + char *i = s.begin(); // begin() doesn't return a pointer + failures++; +#endif + +#ifdef ITER24_F3 + std::string::const_iterator ci; + std::string::iterator i; + if (i - ci) // remove const_ is a warning + i++; + // failures++; only a warning +#endif + +#ifdef ITER24_F4 + std::vector::iterator iv; + std::string::iterator is(iv);// vector is not string + failures++; +#endif + +#ifdef ITER24_F5 + std::vector::iterator iv; + std::string::iterator is; + if (iv == is) // vector is not string + ++iv; + failures++; +#endif + +#ifdef ITER24_F6 + std::vector::const_iterator ci; + std::vector::iterator i = ci; // remove const_ is a warning + ++i; + // failures++; only a warning +#endif + +#ifdef ITER24_F7 + std::vector v(1); + std::vector::const_iterator ci(v.begin()); + *ci = 1; // cannot assign through const_iterator + failures++; +#endif + +#ifdef ITER24_F8 + std::vector v(1); + std::vector::reference r(v.begin()[0]); + r = 1; // cannot assign through reference to const + failures++; +#endif + + return failures; +} + +// libstdc++/6642 +int +test6642() +{ + std::string s; + std::string::iterator it = s.begin(); + std::string::const_iterator cit = s.begin(); + + return it - cit; +} + +int +main() +{ + int failures(0); + + failures += string_stuff(); + + failures += vector_stuff(); + + failures += reverse_stuff(); + + failures += wrong_stuff(); + + failures += test6642(); + + VERIFY(failures == 0); + return 0; +} diff --git a/libstdc++-v3/testsuite/24_iterators/random_access/tag.cc b/libstdc++-v3/testsuite/24_iterators/random_access/tag.cc new file mode 100644 index 00000000000..c2285fdfc50 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/random_access/tag.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2019 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 compile { target c++11 } } + +#include + +using std::random_access_iterator_tag; +using std::bidirectional_iterator_tag; +using std::iterator_traits; + +static_assert( std::is_empty::value ); +static_assert( std::is_trivially_copy_constructible::value ); + +static_assert( std::is_base_of::value ); +static_assert( std::is_convertible::value ); + +static_assert( std::is_same::iterator_category, + random_access_iterator_tag>::value ); diff --git a/libstdc++-v3/testsuite/24_iterators/random_access_iterator/26020.cc b/libstdc++-v3/testsuite/24_iterators/random_access_iterator/26020.cc deleted file mode 100644 index ec2344374d9..00000000000 --- a/libstdc++-v3/testsuite/24_iterators/random_access_iterator/26020.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2006-2019 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 -// . - -// 24.3.4 Iterator operations - -#include -#include -#include - -//libstdc++/26020 -void test01() -{ - using namespace std; - - list ll; - ll.push_back(1); - - list::iterator it(ll.begin()); - - advance(it, 0.5); - - VERIFY( it == ll.begin() ); -} - -int main() -{ - test01(); - return 0; -} diff --git a/libstdc++-v3/testsuite/24_iterators/random_access_iterator/string_vector_iterators.cc b/libstdc++-v3/testsuite/24_iterators/random_access_iterator/string_vector_iterators.cc deleted file mode 100644 index c496254a228..00000000000 --- a/libstdc++-v3/testsuite/24_iterators/random_access_iterator/string_vector_iterators.cc +++ /dev/null @@ -1,607 +0,0 @@ -// 24.1.5 Random access iterators -// 24.3.1 Iterator traits -// (basic_string and vector implementations) -// -// Copyright (C) 1999-2019 Free Software Foundation, Inc. -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program; see the file COPYING3. If not see -// . - - -#include -#include -#include - -int -string_stuff() -{ - int failures(0); - - std::string s("abcde"); - - std::string::iterator i1(s.begin()); - if (*i1 != 'a') - ++failures; - - ++i1; - if (*i1 != 'b') - ++failures; - - if (*i1++ != 'b') - ++failures; - if (*i1 != 'c') - ++failures; - - ++ ++i1; - if (*i1 != 'e') - ++failures; - - --i1; - if (*i1 != 'd') - ++failures; - - if (*i1-- != 'd') - ++failures; - if (*i1 != 'c') - ++failures; - - -- --i1; - if (*i1 != 'a') - ++failures; - - std::string::iterator i2; - i2 = s.end(); - std::iterator_traits::difference_type d1; - d1 = i2 - i1; - if (d1 != 5) - ++failures; - - std::iterator_traits::value_type v1; - v1 = i1[0]; - if (v1 != 'a') - ++failures; - - std::iterator_traits::reference r1(i1[0]); - if (r1 != 'a') - ++failures; - r1 = 'x'; - if (r1 != 'x') - ++failures; - r1 = 'a'; - - if ((i1 != i2) != true) - ++failures; - if ((i1 == i2) != false) - ++failures; - if ((i1 < i2) != true) - ++failures; - if ((i1 > i2) != false) - ++failures; - if ((i1 <= i2) != true) - ++failures; - if ((i1 >= i2) != false) - ++failures; - - std::string::iterator i3; - i3 = i1; - if ((i3 == i1) != true) - ++failures; - - i3 += 5; - if ((i3 == i2) != true) - ++failures; - - i3 -= 5; - if ((i3 == i1) != true) - ++failures; - - if (i3 + 5 != i2) - ++failures; - - if (5 + i3 != i2) - ++failures; - - if (i2 - 5 != i3) - ++failures; - - if (i1[0] != 'a') - ++failures; - - i1[4] = 'x'; - if (i2[-1] != 'x') - ++failures; - i1[4] = 'e'; - - i1[2] = 'x'; - if (i2[-3] != 'x') - ++failures; - i1[2] = 'c'; - - std::string::const_iterator ci1(s.begin()); - if (*ci1 != 'a') - ++failures; - - ++ci1; - if (*ci1 != 'b') - ++failures; - - if (*ci1++ != 'b') - ++failures; - if (*ci1 != 'c') - ++failures; - - ++ ++ci1; - if (*ci1 != 'e') - ++failures; - - --ci1; - if (*ci1 != 'd') - ++failures; - - if (*ci1-- != 'd') - ++failures; - if (*ci1 != 'c') - ++failures; - - -- --ci1; - if (*ci1 != 'a') - ++failures; - - std::string::const_iterator ci2; - ci2 = s.end(); - std::iterator_traits::difference_type d2; - d2 = ci2 - ci1; - if (d2 != 5) - ++failures; - - std::iterator_traits::value_type v2; - v2 = ci1[0]; - if (v2 != 'a') - ++failures; - - std::iterator_traits::reference r2(ci1[0]); - if (r2 != 'a') - ++failures; - - if ((ci1 != ci2) != true) - ++failures; - if ((ci1 == ci2) != false) - ++failures; - if ((ci1 < ci2) != true) - ++failures; - if ((ci1 > ci2) != false) - ++failures; - if ((ci1 <= ci2) != true) - ++failures; - if ((ci1 >= ci2) != false) - ++failures; - - std::string::const_iterator ci3; - ci3 = ci1; - if ((ci3 == ci1) != true) - ++failures; - - ci3 += 5; - if ((ci3 == ci2) != true) - ++failures; - - ci3 -= 5; - if ((ci3 == ci1) != true) - ++failures; - - if (ci3 + 5 != ci2) - ++failures; - - if (5 + ci3 != ci2) - ++failures; - - if (ci2 - 5 != ci3) - ++failures; - - if (ci1[2] != 'c') - ++failures; - - if (ci2[-1] != 'e') - ++failures; - - // iterator and const_iterator - std::string::const_iterator ci4(i1); - if ((ci4 == i1) != true) - ++failures; - if ((ci4 != i1) != false) - ++failures; - if ((ci4 < i1) != false) - ++failures; - if ((ci4 > i1) != false) - ++failures; - if ((ci4 <= i1) != true) - ++failures; - if ((ci4 >= i1) != true) - ++failures; - ci4 = i2; - if ((i2 == ci4) != true) - ++failures; - if ((i2 < ci4) != false) - ++failures; - if ((i2 > ci4) != false) - ++failures; - if ((i2 <= ci4) != true) - ++failures; - if ((i2 >= ci4) != true) - ++failures; - - const std::string cs("ABCDE"); - std::string::const_iterator ci5(cs.begin()); - if (ci5[0] != 'A') - ++failures; - - return failures; -} - -int -vector_stuff() -{ - int failures(0); - - std::vector v; - v.push_back(int(1)); - v.push_back(int(2)); - v.push_back(int(3)); - v.push_back(int(4)); - v.push_back(int(5)); - - std::vector::iterator i1(v.begin()); - if (*i1 != 1) - ++failures; - - ++i1; - if (*i1 != 2) - ++failures; - - if (*i1++ != 2) - ++failures; - if (*i1 != 3) - ++failures; - - ++ ++i1; - if (*i1 != 5) - ++failures; - - --i1; - if (*i1 != 4) - ++failures; - - if (*i1-- != 4) - ++failures; - if (*i1 != 3) - ++failures; - - -- --i1; - if (*i1 != 1) - ++failures; - - std::vector::iterator i2; - i2 = v.end(); - std::iterator_traits::iterator>::difference_type d1; - d1 = i2 - i1; - if (d1 != 5) - ++failures; - - std::iterator_traits::iterator>::value_type v1; - v1 = i1[0]; - if (v1 != 1) - ++failures; - - std::iterator_traits::iterator>::reference r1(i1[0]); - if (r1 != 1) - ++failures; - r1 = 9; - if (r1 != 9) - ++failures; - r1 = 1; - - if ((i1 != i2) != true) - ++failures; - if ((i1 == i2) != false) - ++failures; - if ((i1 < i2) != true) - ++failures; - if ((i1 > i2) != false) - ++failures; - if ((i1 <= i2) != true) - ++failures; - if ((i1 >= i2) != false) - ++failures; - - std::vector::iterator i3; - i3 = i1; - if ((i3 == i1) != true) - ++failures; - - i3 += 5; - if ((i3 == i2) != true) - ++failures; - - i3 -= 5; - if ((i3 == i1) != true) - ++failures; - - if (i3 + 5 != i2) - ++failures; - - if (5 + i3 != i2) - ++failures; - - if (i2 - 5 != i3) - ++failures; - - if (i1[0] != 1) - ++failures; - - i1[4] = 9; - if (i2[-1] != 9) - ++failures; - i1[4] = 5; - - i1[2] = 9; - if (i2[-3] != 9) - ++failures; - i1[2] = 3; - - std::vector::const_iterator ci1(v.begin()); - if (*ci1 != 1) - ++failures; - - ++ci1; - if (*ci1 != 2) - ++failures; - - if (*ci1++ != 2) - ++failures; - if (*ci1 != 3) - ++failures; - - ++ ++ci1; - if (*ci1 != 5) - ++failures; - - --ci1; - if (*ci1 != 4) - ++failures; - - if (*ci1-- != 4) - ++failures; - if (*ci1 != 3) - ++failures; - - -- --ci1; - if (*ci1 != 1) - ++failures; - - std::vector::const_iterator ci2; - ci2 = v.end(); - std::iterator_traits::const_iterator>::difference_type d2; - d2 = ci2 - ci1; - if (d2 != 5) - ++failures; - - std::iterator_traits::const_iterator>::value_type v2; - v2 = ci1[0]; - if (v2 != 1) - ++failures; - - std::iterator_traits::const_iterator>::reference - r2(ci1[0]); - if (r2 != 1) - ++failures; - - if ((ci1 != ci2) != true) - ++failures; - if ((ci1 == ci2) != false) - ++failures; - if ((ci1 < ci2) != true) - ++failures; - if ((ci1 > ci2) != false) - ++failures; - if ((ci1 <= ci2) != true) - ++failures; - if ((ci1 >= ci2) != false) - ++failures; - - std::vector::const_iterator ci3; - ci3 = ci1; - if ((ci3 == ci1) != true) - ++failures; - - ci3 += 5; - if ((ci3 == ci2) != true) - ++failures; - - ci3 -= 5; - if ((ci3 == ci1) != true) - ++failures; - - if (ci3 + 5 != ci2) - ++failures; - - if (5 + ci3 != ci2) - ++failures; - - if (ci2 - 5 != ci3) - ++failures; - - if (ci1[2] != 3) - ++failures; - - if (ci2[-1] != 5) - ++failures; - - // iterator to const_iterator - std::vector::const_iterator ci4(i1); - if ((ci4 == i1) != true) - ++failures; - if ((ci4 != i1) != false) - ++failures; - if ((ci4 < i1) != false) - ++failures; - if ((ci4 > i1) != false) - ++failures; - if ((ci4 <= i1) != true) - ++failures; - if ((ci4 >= i1) != true) - ++failures; - ci4 = i2; - if ((i2 == ci4) != true) - ++failures; - if ((i2 < ci4) != false) - ++failures; - if ((i2 > ci4) != false) - ++failures; - if ((i2 <= ci4) != true) - ++failures; - if ((i2 >= ci4) != true) - ++failures; - - const std::vector cv(v); - std::vector::const_iterator ci5(cv.begin()); - if (ci5[0] != 1) - ++failures; - - std::vector vs; - vs.push_back(std::string("abc")); - std::vector::iterator ivs(vs.begin()); - if (ivs->c_str()[1] != 'b') - ++failures; - - return failures; -} - -int -reverse_stuff() -{ - int failures(0); - - std::string s("abcde"); - - std::string::reverse_iterator ri(s.rbegin()); - if (*ri != 'e') - ++failures; - - std::iterator_traits::difference_type d; - d = s.rend() - ri; - if (d != 5) - ++failures; - - const std::string cs("abcde"); - std::string::const_reverse_iterator cri(cs.rend()); - if (cri - 5 != cs.rbegin()) - ++failures; - - return failures; -} - -// the following should be compiler errors -// flag runtime errors in case they slip through the compiler -int -wrong_stuff() -{ - int failures(0); - -#ifdef ITER24_F1 - extern void f(std::vector::iterator); - std::vector vs[2]; - f(vs); // address of array is not an iterator - failures++; -#endif - -#ifdef ITER24_F2 - std::string s; - char *i = s.begin(); // begin() doesn't return a pointer - failures++; -#endif - -#ifdef ITER24_F3 - std::string::const_iterator ci; - std::string::iterator i; - if (i - ci) // remove const_ is a warning - i++; - // failures++; only a warning -#endif - -#ifdef ITER24_F4 - std::vector::iterator iv; - std::string::iterator is(iv);// vector is not string - failures++; -#endif - -#ifdef ITER24_F5 - std::vector::iterator iv; - std::string::iterator is; - if (iv == is) // vector is not string - ++iv; - failures++; -#endif - -#ifdef ITER24_F6 - std::vector::const_iterator ci; - std::vector::iterator i = ci; // remove const_ is a warning - ++i; - // failures++; only a warning -#endif - -#ifdef ITER24_F7 - std::vector v(1); - std::vector::const_iterator ci(v.begin()); - *ci = 1; // cannot assign through const_iterator - failures++; -#endif - -#ifdef ITER24_F8 - std::vector v(1); - std::vector::reference r(v.begin()[0]); - r = 1; // cannot assign through reference to const - failures++; -#endif - - return failures; -} - -// libstdc++/6642 -int -test6642() -{ - std::string s; - std::string::iterator it = s.begin(); - std::string::const_iterator cit = s.begin(); - - return it - cit; -} - -int -main() -{ - int failures(0); - - failures += string_stuff(); - - failures += vector_stuff(); - - failures += reverse_stuff(); - - failures += wrong_stuff(); - - failures += test6642(); - - VERIFY(failures == 0); - return 0; -} diff --git a/libstdc++-v3/testsuite/24_iterators/range_operations/advance_debug_neg.cc b/libstdc++-v3/testsuite/24_iterators/range_operations/advance_debug_neg.cc new file mode 100644 index 00000000000..6a21da30e3f --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/range_operations/advance_debug_neg.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2019 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-options "-std=gnu++2a -D_GLIBCXX_DEBUG" } +// { dg-do compile { xfail c++2a } } + +#include +#include + +void +test01() +{ + int a[2] = { }; + __gnu_test::test_container c(a); + auto iter = c.begin(); + std::ranges::advance(iter, -1); +}