[libcxx-commits] [libcxx] 41bdf64 - [libc++] Update all the pre-defined iterator types for C++20

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 31 08:57:41 PDT 2021


Author: Louis Dionne
Date: 2021-05-31T11:59:40-04:00
New Revision: 41bdf64d3e94f56870b07bed579ff2a54f0f1ca6

URL: https://github.com/llvm/llvm-project/commit/41bdf64d3e94f56870b07bed579ff2a54f0f1ca6
DIFF: https://github.com/llvm/llvm-project/commit/41bdf64d3e94f56870b07bed579ff2a54f0f1ca6.diff

LOG: [libc++] Update all the pre-defined iterator types for C++20

Make sure we provide the correct It::difference_type member and update
the tests and synopses to be accurate.

Supersedes D102657 and D103101 (thanks to the original authors).

Differential Revision: https://reviews.llvm.org/D103273

Added: 
    libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/default.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/default.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/default.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.cons.des/default.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.cons/default.pass.cpp

Modified: 
    libcxx/include/__memory/raw_storage_iterator.h
    libcxx/include/iterator
    libcxx/include/memory
    libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/iterator_concept_conformance.compile.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/types.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/iterator_concept_conformance.compile.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/types.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/iterator_concept_conformance.compile.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
    libcxx/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
    libcxx/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostream.iterator/iterator_concept_conformance.compile.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/iterator_concept_conformance.compile.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
    libcxx/test/std/utilities/memory/storage.iterator/types.compile.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__memory/raw_storage_iterator.h b/libcxx/include/__memory/raw_storage_iterator.h
index b43000b179486..e8f82b219e675 100644
--- a/libcxx/include/__memory/raw_storage_iterator.h
+++ b/libcxx/include/__memory/raw_storage_iterator.h
@@ -40,7 +40,11 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
 public:
     typedef output_iterator_tag iterator_category;
     typedef void                value_type;
+#if _LIBCPP_STD_VER > 17
+    typedef ptr
diff _t           
diff erence_type;
+#else
     typedef void                
diff erence_type;
+#endif
     typedef void                pointer;
     typedef void                reference;
 

diff  --git a/libcxx/include/iterator b/libcxx/include/iterator
index d4be4826b234c..caa36733d6594 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -242,16 +242,19 @@ constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14
 
 template <class Container>
 class back_insert_iterator
+    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
 {
 protected:
     Container* container;
 public:
     typedef Container                   container_type;
     typedef void                        value_type;
-    typedef void                        
diff erence_type;
+    typedef void                        
diff erence_type; // until C++20
+    typedef ptr
diff _t                   
diff erence_type; // since C++20
     typedef void                        reference;
     typedef void                        pointer;
 
+    constexpr back_insert_iterator() noexcept = default; // since C++20
     explicit back_insert_iterator(Container& x);  // constexpr in C++20
     back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
     back_insert_iterator& operator*();  // constexpr in C++20
@@ -263,16 +266,19 @@ template <class Container> back_insert_iterator<Container> back_inserter(Contain
 
 template <class Container>
 class front_insert_iterator
+    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
 {
 protected:
     Container* container;
 public:
     typedef Container                    container_type;
     typedef void                         value_type;
-    typedef void                         
diff erence_type;
+    typedef void                         
diff erence_type; // until C++20
+    typedef ptr
diff _t                    
diff erence_type; // since C++20
     typedef void                         reference;
     typedef void                         pointer;
 
+    constexpr front_insert_iterator() noexcept = default; // since C++20
     explicit front_insert_iterator(Container& x);  // constexpr in C++20
     front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
     front_insert_iterator& operator*();  // constexpr in C++20
@@ -284,6 +290,7 @@ template <class Container> front_insert_iterator<Container> front_inserter(Conta
 
 template <class Container>
 class insert_iterator
+    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
 {
 protected:
     Container* container;
@@ -291,10 +298,12 @@ protected:
 public:
     typedef Container              container_type;
     typedef void                   value_type;
-    typedef void                   
diff erence_type;
+    typedef void                   
diff erence_type; // until C++20
+    typedef ptr
diff _t              
diff erence_type; // since C++20
     typedef void                   reference;
     typedef void                   pointer;
 
+    insert_iterator() = default; // since C++20
     insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
     insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
     insert_iterator& operator*();  // constexpr in C++20
@@ -380,9 +389,15 @@ class istream_iterator
     : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
 {
 public:
-    typedef charT char_type;
-    typedef traits traits_type;
-    typedef basic_istream<charT,traits> istream_type;
+    typedef input_iterator_tag           iterator_category;
+    typedef T                            value_type;
+    typedef Distance                     
diff erence_type;
+    typedef const T*                     pointer;
+    typedef const T&                     reference;
+
+    typedef charT                        char_type;
+    typedef traits                       traits_type;
+    typedef basic_istream<charT, traits> istream_type;
 
     constexpr istream_iterator();
     istream_iterator(istream_type& s);
@@ -404,13 +419,21 @@ bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
 
 template <class T, class charT = char, class traits = char_traits<charT> >
 class ostream_iterator
-    : public iterator<output_iterator_tag, void, void, void ,void> // until C++17
+    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
 {
 public:
+    typedef output_iterator_tag         iterator_category;
+    typedef void                        value_type;
+    typedef void                        
diff erence_type; // until C++20
+    typedef ptr
diff _t                   
diff erence_type; // since C++20
+    typedef void                        pointer;
+    typedef void                        reference;
+
     typedef charT char_type;
     typedef traits traits_type;
     typedef basic_ostream<charT,traits> ostream_type;
 
+    constexpr ostream_iterator() noexcept = default; // since C++20
     ostream_iterator(ostream_type& s);
     ostream_iterator(ostream_type& s, const charT* delimiter);
     ostream_iterator(const ostream_iterator& x);
@@ -424,16 +447,20 @@ public:
 
 template<class charT, class traits = char_traits<charT> >
 class istreambuf_iterator
-    : public iterator<input_iterator_tag, charT,                // until C++17
-                      typename traits::off_type, unspecified,
-                      charT>
+    : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17
 {
 public:
-    typedef charT                         char_type;
-    typedef traits                        traits_type;
-    typedef typename traits::int_type     int_type;
-    typedef basic_streambuf<charT,traits> streambuf_type;
-    typedef basic_istream<charT,traits>   istream_type;
+    typedef input_iterator_tag              iterator_category;
+    typedef charT                           value_type;
+    typedef traits::off_type                
diff erence_type;
+    typedef unspecified                     pointer;
+    typedef charT                           reference;
+
+    typedef charT                           char_type;
+    typedef traits                          traits_type;
+    typedef traits::int_type                int_type;
+    typedef basic_streambuf<charT, traits>  streambuf_type;
+    typedef basic_istream<charT, traits>    istream_type;
 
     istreambuf_iterator() noexcept;
     istreambuf_iterator(istream_type& s) noexcept;
@@ -460,11 +487,19 @@ class ostreambuf_iterator
     : public iterator<output_iterator_tag, void, void, void, void> // until C++17
 {
 public:
-    typedef charT                         char_type;
-    typedef traits                        traits_type;
-    typedef basic_streambuf<charT,traits> streambuf_type;
-    typedef basic_ostream<charT,traits>   ostream_type;
-
+    typedef output_iterator_tag            iterator_category;
+    typedef void                           value_type;
+    typedef void                           
diff erence_type; // until C++20
+    typedef ptr
diff _t                      
diff erence_type; // since C++20
+    typedef void                           pointer;
+    typedef void                           reference;
+
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef basic_streambuf<charT, traits> streambuf_type;
+    typedef basic_ostream<charT, traits>   ostream_type;
+
+    constexpr ostreambuf_iterator() noexcept = default; // since C++20
     ostreambuf_iterator(ostream_type& s) noexcept;
     ostreambuf_iterator(streambuf_type* s) noexcept;
     ostreambuf_iterator& operator=(charT c);
@@ -851,11 +886,18 @@ protected:
 public:
     typedef output_iterator_tag iterator_category;
     typedef void value_type;
+#if _LIBCPP_STD_VER > 17
+    typedef ptr
diff _t 
diff erence_type;
+#else
     typedef void 
diff erence_type;
+#endif
     typedef void pointer;
     typedef void reference;
     typedef _Container container_type;
 
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY constexpr back_insert_iterator() noexcept = default;
+#endif
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
         {container->push_back(__value_); return *this;}
@@ -889,11 +931,18 @@ protected:
 public:
     typedef output_iterator_tag iterator_category;
     typedef void value_type;
+#if _LIBCPP_STD_VER > 17
+    typedef ptr
diff _t 
diff erence_type;
+#else
     typedef void 
diff erence_type;
+#endif
     typedef void pointer;
     typedef void reference;
     typedef _Container container_type;
 
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY constexpr front_insert_iterator() noexcept = default;
+#endif
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
         {container->push_front(__value_); return *this;}
@@ -928,11 +977,18 @@ protected:
 public:
     typedef output_iterator_tag iterator_category;
     typedef void value_type;
+#if _LIBCPP_STD_VER > 17
+    typedef ptr
diff _t 
diff erence_type;
+#else
     typedef void 
diff erence_type;
+#endif
     typedef void pointer;
     typedef void reference;
     typedef _Container container_type;
 
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY insert_iterator() = default;
+#endif
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
         : container(_VSTD::addressof(__x)), iter(__i) {}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
@@ -1037,7 +1093,7 @@ public:
     typedef output_iterator_tag             iterator_category;
     typedef void                            value_type;
 #if _LIBCPP_STD_VER > 17
-    typedef std::ptr
diff _t                  
diff erence_type;
+    typedef ptr
diff _t                       
diff erence_type;
 #else
     typedef void                            
diff erence_type;
 #endif
@@ -1051,6 +1107,9 @@ private:
     ostream_type* __out_stream_;
     const char_type* __delim_;
 public:
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY constexpr ostream_iterator() noexcept = default;
+#endif
     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
         : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
@@ -1159,7 +1218,7 @@ public:
     typedef output_iterator_tag                 iterator_category;
     typedef void                                value_type;
 #if _LIBCPP_STD_VER > 17
-    typedef std::ptr
diff _t                      
diff erence_type;
+    typedef ptr
diff _t                           
diff erence_type;
 #else
     typedef void                                
diff erence_type;
 #endif
@@ -1173,6 +1232,9 @@ public:
 private:
     streambuf_type* __sbuf_;
 public:
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY constexpr ostreambuf_iterator() noexcept = default;
+#endif
     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
         : __sbuf_(__s.rdbuf()) {}
     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT

diff  --git a/libcxx/include/memory b/libcxx/include/memory
index 46acab6aa8f49..c7480708ebe90 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -153,10 +153,17 @@ template <class T, class U>
 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20
 
 template <class OutputIterator, class T>
-class raw_storage_iterator
+class raw_storage_iterator // deprecated in C++17, removed in C++20
     : public iterator<output_iterator_tag, void, void, void, void> // until C++17
 {
 public:
+    typedef output_iterator_tag iterator_category;
+    typedef void                value_type;
+    typedef void                
diff erence_type; // until C++20
+    typedef ptr
diff _t           
diff erence_type; // since C++20
+    typedef void                pointer;
+    typedef void                reference;
+
     explicit raw_storage_iterator(OutputIterator x);
     raw_storage_iterator& operator*();
     raw_storage_iterator& operator=(const T& element);

diff  --git a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
index 8a0ae891f4f79..2ce231e0d6b7c 100644
--- a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
@@ -50,12 +50,12 @@ constexpr bool has_iterator_concept_v = requires {
   typename Traits::iterator_concept;
 };
 
-template <class Iter, class Category, class Diff = void>
+template <class Iter, class Category>
 constexpr bool testIOIterator() {
   using Traits = std::iterator_traits<Iter>;
   static_assert(std::same_as<typename Traits::iterator_category, Category>);
   static_assert(std::same_as<typename Traits::value_type, void>);
-  static_assert(std::same_as<typename Traits::
diff erence_type, Diff>);
+  static_assert(std::same_as<typename Traits::
diff erence_type, std::ptr
diff _t>);
   static_assert(std::same_as<typename Traits::reference, void>);
   static_assert(std::same_as<typename Traits::pointer, void>);
   static_assert(!has_iterator_concept_v<Traits>);
@@ -200,8 +200,8 @@ static_assert(testConstWithoutConcept<std::istream_iterator<int, char>, int, std
 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 static_assert(testWithoutConcept<std::istreambuf_iterator<char>, char, long long, char, char*, std::input_iterator_tag>());
 static_assert(testWithoutConcept<std::move_iterator<int*>, int, std::ptr
diff _t, int&&, int*, std::random_access_iterator_tag>());
-static_assert(testIOIterator<std::ostream_iterator<int, char>, std::output_iterator_tag, std::ptr
diff _t>());
-static_assert(testIOIterator<std::ostreambuf_iterator<int, char>, std::output_iterator_tag, std::ptr
diff _t>());
+static_assert(testIOIterator<std::ostream_iterator<int, char>, std::output_iterator_tag>());
+static_assert(testIOIterator<std::ostreambuf_iterator<int, char>, std::output_iterator_tag>());
 static_assert(testConstWithoutConcept<std::cregex_iterator, std::cmatch, std::forward_iterator_tag>());
 static_assert(testConstWithoutConcept<std::cregex_token_iterator, std::csub_match, std::forward_iterator_tag>());
 #endif // !_LIBCPP_HAS_NO_LOCALIZATION

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/default.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/default.pass.cpp
new file mode 100644
index 0000000000000..ff5801c11e6e8
--- /dev/null
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/default.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <iterator>
+
+// class back_insert_iterator
+
+// constexpr back_insert_iterator() noexcept = default;
+
+#include <iterator>
+#include <vector>
+
+#include "test_macros.h"
+
+struct T { };
+using Container = std::vector<T>;
+
+constexpr bool test() {
+    std::back_insert_iterator<Container> it;
+    (void)it;
+    return true;
+}
+
+int main(int, char**) {
+    ASSERT_NOEXCEPT(std::back_insert_iterator<Container>());
+
+    test();
+    static_assert(test());
+
+    return 0;
+}

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/iterator_concept_conformance.compile.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/iterator_concept_conformance.compile.pass.cpp
index 2a09fce92423c..429379c08275c 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/iterator_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/iterator_concept_conformance.compile.pass.cpp
@@ -19,8 +19,8 @@
 using iterator = std::back_insert_iterator<std::vector<int> >;
 static_assert(!std::indirectly_readable<iterator>);
 static_assert(std::indirectly_writable<iterator, int>);
-static_assert(!std::weakly_incrementable<iterator>);
-static_assert(!std::input_or_output_iterator<iterator>);
+static_assert(std::weakly_incrementable<iterator>);
+static_assert(std::input_or_output_iterator<iterator>);
 static_assert(!std::sentinel_for<iterator, iterator>);
 static_assert(!std::sized_sentinel_for<iterator, iterator>);
 static_assert(!std::input_iterator<iterator>);

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/types.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/types.pass.cpp
index baf2383d9f62e..f8d3e2b4fdc7b 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iterator/types.pass.cpp
@@ -13,13 +13,16 @@
 // Test nested types and data member:
 
 // template <BackInsertionContainer Cont>
-// class back_insert_iterator {
+// class back_insert_iterator
+//  : public iterator<output_iterator_tag, void, void, void, void> // until C++17
+// {
 // protected:
 //   Cont* container;
 // public:
 //   typedef Cont                        container_type;
 //   typedef void                        value_type;
-//   typedef void                        
diff erence_type;
+//   typedef void                        
diff erence_type; // until C++20
+//   typedef ptr
diff _t                   
diff erence_type; // since C++20
 //   typedef void                        reference;
 //   typedef void                        pointer;
 // };
@@ -48,7 +51,11 @@ test()
     q.test();
     static_assert((std::is_same<typename R::container_type, C>::value), "");
     static_assert((std::is_same<typename R::value_type, void>::value), "");
+#if TEST_STD_VER > 17
+    static_assert((std::is_same<typename R::
diff erence_type, std::ptr
diff _t>::value), "");
+#else
     static_assert((std::is_same<typename R::
diff erence_type, void>::value), "");
+#endif
     static_assert((std::is_same<typename R::reference, void>::value), "");
     static_assert((std::is_same<typename R::pointer, void>::value), "");
     static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/default.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/default.pass.cpp
new file mode 100644
index 0000000000000..6ee4358c2695a
--- /dev/null
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/default.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <iterator>
+
+// class front_insert_iterator
+
+// constexpr front_insert_iterator() noexcept = default;
+
+#include <iterator>
+#include <vector>
+
+#include "test_macros.h"
+
+struct T { };
+using Container = std::vector<T>;
+
+constexpr bool test() {
+    std::front_insert_iterator<Container> it;
+    (void)it;
+    return true;
+}
+
+int main(int, char**) {
+    ASSERT_NOEXCEPT(std::front_insert_iterator<Container>());
+
+    test();
+    static_assert(test());
+
+    return 0;
+}

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/iterator_concept_conformance.compile.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/iterator_concept_conformance.compile.pass.cpp
index 96d969c19b0c5..e061896e5b2d0 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/iterator_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/iterator_concept_conformance.compile.pass.cpp
@@ -19,8 +19,8 @@
 using iterator = std::front_insert_iterator<std::list<int> >;
 static_assert(!std::indirectly_readable<iterator>);
 static_assert(std::indirectly_writable<iterator, int>);
-static_assert(!std::weakly_incrementable<iterator>);
-static_assert(!std::input_or_output_iterator<iterator>);
+static_assert(std::weakly_incrementable<iterator>);
+static_assert(std::input_or_output_iterator<iterator>);
 static_assert(!std::sentinel_for<iterator, iterator>);
 static_assert(!std::sized_sentinel_for<iterator, iterator>);
 static_assert(!std::input_iterator<iterator>);

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/types.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/types.pass.cpp
index 4d122538b4cd0..f71ba368ab861 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iterator/types.pass.cpp
@@ -13,13 +13,16 @@
 // Test nested types and data member:
 
 // template <class Container>
-// class front_insert_iterator {
+// class front_insert_iterator
+//  : public iterator<output_iterator_tag, void, void, void, void> // until C++17
+// {
 // protected:
 //   Container* container;
 // public:
 //   typedef Container                   container_type;
 //   typedef void                        value_type;
-//   typedef void                        
diff erence_type;
+//   typedef void                        
diff erence_type; // until C++20
+//   typedef ptr
diff _t                   
diff erence_type; // since C++20
 //   typedef void                        reference;
 //   typedef void                        pointer;
 //   typedef output_iterator_tag         iterator_category;
@@ -49,7 +52,11 @@ test()
     q.test();
     static_assert((std::is_same<typename R::container_type, C>::value), "");
     static_assert((std::is_same<typename R::value_type, void>::value), "");
+#if TEST_STD_VER > 17
+    static_assert((std::is_same<typename R::
diff erence_type, std::ptr
diff _t>::value), "");
+#else
     static_assert((std::is_same<typename R::
diff erence_type, void>::value), "");
+#endif
     static_assert((std::is_same<typename R::reference, void>::value), "");
     static_assert((std::is_same<typename R::pointer, void>::value), "");
     static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/default.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/default.pass.cpp
new file mode 100644
index 0000000000000..3e1ccfb7cba8d
--- /dev/null
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/default.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <iterator>
+
+// class insert_iterator
+
+// insert_iterator() = default;
+
+#include <iterator>
+#include <vector>
+
+struct T { };
+using Container = std::vector<T>;
+
+int main(int, char**) {
+    std::insert_iterator<Container> it; (void)it;
+    return 0;
+}

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/iterator_concept_conformance.compile.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/iterator_concept_conformance.compile.pass.cpp
index 6fc9b0e3f0b7f..b4cdcd0303eaf 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/iterator_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/iterator_concept_conformance.compile.pass.cpp
@@ -19,7 +19,7 @@
 using iterator = std::insert_iterator<std::vector<int> >;
 static_assert(!std::indirectly_readable<iterator>);
 static_assert(std::indirectly_writable<iterator, int>);
-static_assert(!std::weakly_incrementable<iterator>);
-static_assert(!std::input_or_output_iterator<iterator>);
+static_assert(std::weakly_incrementable<iterator>);
+static_assert(std::input_or_output_iterator<iterator>);
 static_assert(!std::sentinel_for<iterator, iterator>);
 static_assert(!std::input_iterator<iterator>);

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
index d33079229cc66..08864868342ae 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
@@ -13,14 +13,17 @@
 // Test nested types and data members:
 
 // template <InsertionContainer Cont>
-// class insert_iterator {
+// class insert_iterator
+//  : public iterator<output_iterator_tag, void, void, void, void> // until C++17
+// {
 // protected:
 //   Cont* container;
 //   Cont::iterator iter;
 // public:
 //   typedef Cont                   container_type;
 //   typedef void                   value_type;
-//   typedef void                   
diff erence_type;
+//   typedef void                   
diff erence_type; // until C++20
+//   typedef ptr
diff _t              
diff erence_type; // since C++20
 //   typedef void                   reference;
 //   typedef void                   pointer;
 // };
@@ -52,7 +55,11 @@ test()
     q.test();
     static_assert((std::is_same<typename R::container_type, C>::value), "");
     static_assert((std::is_same<typename R::value_type, void>::value), "");
+#if TEST_STD_VER > 17
+    static_assert((std::is_same<typename R::
diff erence_type, std::ptr
diff _t>::value), "");
+#else
     static_assert((std::is_same<typename R::
diff erence_type, void>::value), "");
+#endif
     static_assert((std::is_same<typename R::reference, void>::value), "");
     static_assert((std::is_same<typename R::pointer, void>::value), "");
     static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");

diff  --git a/libcxx/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp b/libcxx/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
index 2018be6c7d07e..6b7b1f9cf89bd 100644
--- a/libcxx/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
@@ -10,11 +10,20 @@
 
 // template <class T, class charT = char, class traits = char_traits<charT>,
 //           class Distance = ptr
diff _t>
-// class istream_iterator {
+// class istream_iterator
+//  : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
+// {
 // public:
-//     typedef charT char_type;
-//     typedef traits traits_type;
-//     typedef basic_istream<charT,traits> istream_type;
+//     typedef input_iterator_tag           iterator_category;
+//     typedef T                            value_type;
+//     typedef Distance                     
diff erence_type;
+//     typedef const T*                     pointer;
+//     typedef const T&                     reference;
+//
+//     typedef basic_istream<charT, Traits> istream_type;
+//     typedef charT                        char_type;
+//     typedef traits                       traits_type;
+//     typedef basic_istream<charT, traits> istream_type;
 //     ...
 //
 // Before C++17, we have:

diff  --git a/libcxx/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp b/libcxx/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp
index d9cd65ad7f949..257a26627f29f 100644
--- a/libcxx/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/istreambuf.iterator/types.pass.cpp
@@ -9,13 +9,21 @@
 // <iterator>
 
 // template<class charT, class traits = char_traits<charT> >
-// class istreambuf_iterator {
+// class istreambuf_iterator
+//  : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17
+// {
 // public:
-//     typedef charT                         char_type;
-//     typedef traits                        traits_type;
-//     typedef typename traits::int_type     int_type;
-//     typedef basic_streambuf<charT,traits> streambuf_type;
-//     typedef basic_istream<charT,traits>   istream_type;
+//     typedef input_iterator_tag             iterator_category;
+//     typedef charT                          value_type;
+//     typedef traits::off_type               
diff erence_type;
+//     typedef unspecified                    pointer;
+//     typedef charT                          reference;
+//
+//     typedef charT                          char_type;
+//     typedef traits                         traits_type;
+//     typedef traits::int_type               int_type;
+//     typedef basic_streambuf<charT, traits> streambuf_type;
+//     typedef basic_istream<charT, traits>   istream_type;
 //     ...
 //
 // All specializations of istreambuf_iterator shall have a trivial copy constructor,

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/iterator_concept_conformance.compile.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/iterator_concept_conformance.compile.pass.cpp
index a814a7d2ed36f..a48e56c4b53ee 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/iterator_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/iterator_concept_conformance.compile.pass.cpp
@@ -19,8 +19,8 @@
 using iterator = std::ostream_iterator<int, std::ostream>;
 static_assert(!std::indirectly_readable<iterator>);
 static_assert(std::indirectly_writable<iterator, int>);
-static_assert(!std::weakly_incrementable<iterator>);
-static_assert(!std::input_or_output_iterator<iterator>);
+static_assert(std::weakly_incrementable<iterator>);
+static_assert(std::input_or_output_iterator<iterator>);
 static_assert(!std::sentinel_for<iterator, iterator>);
 static_assert(!std::sized_sentinel_for<iterator, iterator>);
 static_assert(!std::input_iterator<iterator>);

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.cons.des/default.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.cons.des/default.pass.cpp
new file mode 100644
index 0000000000000..c19e2938a7467
--- /dev/null
+++ b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.cons.des/default.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <iterator>
+
+// class ostream_iterator
+
+// constexpr ostream_iterator() noexcept = default;
+
+#include <iterator>
+#include <string> // char_traits
+
+#include "test_macros.h"
+
+struct MyTraits : std::char_traits<char> {
+    MyTraits();  // This should not be called.
+};
+
+constexpr bool test() {
+    std::ostream_iterator<int> it;
+    (void)it;
+    std::ostream_iterator<int, char, MyTraits> wit;
+    (void)wit;
+    return true;
+}
+
+int main(int, char**) {
+    ASSERT_NOEXCEPT(std::ostream_iterator<int>());
+    ASSERT_NOEXCEPT(std::ostream_iterator<int, char, MyTraits>());
+
+    test();
+    static_assert(test());
+
+    return 0;
+}

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
index b5ac8199e5208..042feebf0a0d6 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
@@ -10,11 +10,20 @@
 
 // template <class T, class charT = char, class traits = char_traits<charT>,
 //           class Distance = ptr
diff _t>
-// class ostream_iterator {
+// class ostream_iterator
+//  : public iterator<output_iterator_tag, void, void, void, void> // until C++17
+// {
 // public:
-//     typedef charT char_type;
-//     typedef traits traits_type;
-//     typedef basic_istream<charT,traits> istream_type;
+//     typedef output_iterator_tag          iterator_category;
+//     typedef void                         value_type;
+//     typedef void                         
diff erence_type; // until C++20
+//     typedef ptr
diff _t                    
diff erence_type; // since C++20
+//     typedef void                         pointer;
+//     typedef void                         reference;
+//
+//     typedef charT                        char_type;
+//     typedef traits                       traits_type;
+//     typedef basic_ostream<charT, traits> ostream_type;
 //     ...
 
 #include <cstddef>

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/iterator_concept_conformance.compile.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/iterator_concept_conformance.compile.pass.cpp
index 9cd2dad9d0e9d..67672947d2078 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/iterator_concept_conformance.compile.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/iterator_concept_conformance.compile.pass.cpp
@@ -20,8 +20,8 @@
 using iterator = std::ostreambuf_iterator<char>;
 static_assert(!std::indirectly_readable<iterator>);
 static_assert(std::indirectly_writable<iterator, char>);
-static_assert(!std::weakly_incrementable<iterator>);
-static_assert(!std::input_or_output_iterator<iterator>);
+static_assert(std::weakly_incrementable<iterator>);
+static_assert(std::input_or_output_iterator<iterator>);
 static_assert(!std::sentinel_for<iterator, iterator>);
 static_assert(!std::sized_sentinel_for<iterator, iterator>);
 static_assert(!std::input_iterator<iterator>);

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.cons/default.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.cons/default.pass.cpp
new file mode 100644
index 0000000000000..63a05fbe63efb
--- /dev/null
+++ b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.cons/default.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <iterator>
+
+// class ostreambuf_iterator
+
+// constexpr ostreambuf_iterator() noexcept = default;
+
+#include <iterator>
+
+#include "test_macros.h"
+
+constexpr bool test() {
+    std::ostreambuf_iterator<char> it;
+    (void)it;
+    std::ostreambuf_iterator<wchar_t> wit;
+    (void)wit;
+    return true;
+}
+
+int main(int, char**) {
+    ASSERT_NOEXCEPT(std::ostreambuf_iterator<char>());
+    ASSERT_NOEXCEPT(std::ostreambuf_iterator<wchar_t>());
+
+    test();
+    static_assert(test());
+
+    return 0;
+}

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
index 4d3925f2e5285..b1260aa1a9708 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
@@ -9,13 +9,22 @@
 // <iterator>
 
 // template <class charT, class traits = char_traits<charT> >
-// class ostreambuf_iterator {
+// class ostreambuf_iterator
+//  : public iterator<output_iterator_tag, void, void, void, void> // until C++17
+// {
 // public:
-//   typedef charT                          char_type;
-//   typedef traits                         traits_type;
-//   typedef basic_streambuf<charT, traits> streambuf_type;
-//   typedef basic_ostream<charT, traits>   ostream_type;
-//   ...
+//     typedef output_iterator_tag            iterator_category;
+//     typedef void                           value_type;
+//     typedef void                           
diff erence_type; // until C++20
+//     typedef ptr
diff _t                      
diff erence_type; // since C++20
+//     typedef void                           pointer;
+//     typedef void                           reference;
+//
+//     typedef charT                          char_type;
+//     typedef traits                         traits_type;
+//     typedef basic_streambuf<charT, traits> streambuf_type;
+//     typedef basic_ostream<charT, traits>   ostream_type;
+//     ...
 
 #include <cstddef>
 #include <iterator>

diff  --git a/libcxx/test/std/utilities/memory/storage.iterator/types.compile.pass.cpp b/libcxx/test/std/utilities/memory/storage.iterator/types.compile.pass.cpp
index 734e8d9937ef8..0772124091134 100644
--- a/libcxx/test/std/utilities/memory/storage.iterator/types.compile.pass.cpp
+++ b/libcxx/test/std/utilities/memory/storage.iterator/types.compile.pass.cpp
@@ -11,15 +11,22 @@
 
 // raw_storage_iterator associated types
 
+#include <cstddef>
 #include <memory>
 #include <type_traits>
 
+#include "test_macros.h"
+
 struct T;
 typedef T* OutputIt;
 typedef std::raw_storage_iterator<OutputIt, T> It;
 
 static_assert(std::is_same<It::iterator_category, std::output_iterator_tag>::value, "");
 static_assert(std::is_same<It::value_type, void>::value, "");
+#if TEST_STD_VER > 17
+static_assert(std::is_same<It::
diff erence_type, std::ptr
diff _t>::value, "");
+#else
 static_assert(std::is_same<It::
diff erence_type, void>::value, "");
+#endif
 static_assert(std::is_same<It::pointer, void>::value, "");
 static_assert(std::is_same<It::reference, void>::value, "");


        


More information about the libcxx-commits mailing list