From 9aeb3bef2cae234dbb90609392e536bafc09365c Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 30 Oct 2019 15:48:11 +0000 Subject: [PATCH] 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 --- libstdc++-v3/ChangeLog | 37 ++++++ libstdc++-v3/include/bits/stl_bvector.h | 8 ++ libstdc++-v3/include/bits/stl_iterator.h | 8 ++ .../include/bits/streambuf_iterator.h | 15 +++ .../vector/bool/iterator_c++20.cc | 30 +++++ .../24_iterators/bidirectional/concept.cc | 81 ++++++++++++ .../24_iterators/bidirectional/tag.cc | 32 +++++ .../24_iterators/contiguous/concept.cc | 64 +++++++-- .../testsuite/24_iterators/contiguous/tag.cc | 4 + .../testsuite/24_iterators/forward/concept.cc | 86 +++++++++++++ .../testsuite/24_iterators/forward/tag.cc | 32 +++++ .../testsuite/24_iterators/input/concept.cc | 89 +++++++++++++ .../testsuite/24_iterators/input/tag.cc | 32 +++++ .../requirements/typedefs.cc | 51 +++++++- .../26020.cc | 0 .../requirements/typedefs.cc | 46 +++++++ .../testsuite/24_iterators/output/concept.cc | 121 ++++++++++++++++++ .../testsuite/24_iterators/output/tag.cc | 32 +++++ .../24_iterators/random_access/concept.cc | 76 +++++++++++ .../string_vector_iterators.cc | 0 .../24_iterators/random_access/tag.cc | 35 +++++ .../range_operations/advance_debug_neg.cc | 31 +++++ 22 files changed, 899 insertions(+), 11 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/iterator_c++20.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/bidirectional/concept.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/bidirectional/tag.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/forward/concept.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/forward/tag.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/input/concept.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/input/tag.cc rename libstdc++-v3/testsuite/24_iterators/{random_access_iterator => operations}/26020.cc (100%) create mode 100644 libstdc++-v3/testsuite/24_iterators/output/concept.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/output/tag.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/random_access/concept.cc rename libstdc++-v3/testsuite/24_iterators/{random_access_iterator => random_access}/string_vector_iterators.cc (100%) create mode 100644 libstdc++-v3/testsuite/24_iterators/random_access/tag.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/range_operations/advance_debug_neg.cc 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/random_access_iterator/26020.cc b/libstdc++-v3/testsuite/24_iterators/operations/26020.cc similarity index 100% rename from libstdc++-v3/testsuite/24_iterators/random_access_iterator/26020.cc rename to libstdc++-v3/testsuite/24_iterators/operations/26020.cc 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_iterator/string_vector_iterators.cc b/libstdc++-v3/testsuite/24_iterators/random_access/string_vector_iterators.cc similarity index 100% rename from libstdc++-v3/testsuite/24_iterators/random_access_iterator/string_vector_iterators.cc rename to libstdc++-v3/testsuite/24_iterators/random_access/string_vector_iterators.cc 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/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); +} -- 2.30.2