[libcxx-commits] [libcxx] 8a5f0d8 - [libc++] [test] Constexpr-ify a couple of insert-iterator tests.

Arthur O'Dwyer via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 28 12:16:19 PDT 2021


Author: Arthur O'Dwyer
Date: 2021-05-28T15:15:50-04:00
New Revision: 8a5f0d883832aa088460df87df99c40d8f238655

URL: https://github.com/llvm/llvm-project/commit/8a5f0d883832aa088460df87df99c40d8f238655
DIFF: https://github.com/llvm/llvm-project/commit/8a5f0d883832aa088460df87df99c40d8f238655.diff

LOG: [libc++] [test] Constexpr-ify a couple of insert-iterator tests.

This should have been done in D96385; thanks ldionne for the catch!
Also, make the back/front inserter behavior tests a little more thorough,
which incidentally caught a cut-and-paste-bug in `nasty_list`, so fix that.

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

Added: 
    

Modified: 
    libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/container.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.inserter/test.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.inserter/test.pass.cpp
    libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/test.pass.cpp
    libcxx/test/support/nasty_containers.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/container.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/container.pass.cpp
index 0c43c15d014ea..4b9745a1c3639 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/container.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.insert.iter.cons/container.pass.cpp
@@ -10,25 +10,30 @@
 
 // back_insert_iterator
 
-// explicit back_insert_iterator(Cont& x);
+// explicit back_insert_iterator(Cont& x); // constexpr in C++20
 
 #include <iterator>
 #include <vector>
-#include "nasty_containers.h"
 
 #include "test_macros.h"
+#include "nasty_containers.h"
+#include "test_constexpr_container.h"
 
 template <class C>
-void
+TEST_CONSTEXPR_CXX20 bool
 test(C c)
 {
     std::back_insert_iterator<C> i(c);
+    return true;
 }
 
 int main(int, char**)
 {
     test(std::vector<int>());
     test(nasty_vector<int>());
-
-  return 0;
+#if TEST_STD_VER >= 20
+    test(ConstexprFixedCapacityDeque<int, 10>());
+    static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
+#endif
+    return 0;
 }

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.inserter/test.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.inserter/test.pass.cpp
index 192d5a1595607..6d682e166d5b8 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.inserter/test.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.inserter/test.pass.cpp
@@ -10,29 +10,41 @@
 
 // template <BackInsertionContainer Cont>
 //   back_insert_iterator<Cont>
-//   back_inserter(Cont& x);
+//   back_inserter(Cont& x); // constexpr in C++20
+
+// template <BackInsertionContainer Cont>
+//   front_insert_iterator<Cont>
+//   front_inserter(Cont& x); // constexpr in C++20
 
-#include <iterator>
-#include <vector>
 #include <cassert>
-#include "nasty_containers.h"
+#include <iterator>
+#include <list>
 
 #include "test_macros.h"
+#include "nasty_containers.h"
+#include "test_constexpr_container.h"
 
 template <class C>
-void
+TEST_CONSTEXPR_CXX20 bool
 test(C c)
 {
     std::back_insert_iterator<C> i = std::back_inserter(c);
-    i = 0;
+    i = 3;
     assert(c.size() == 1);
-    assert(c.back() == 0);
+    assert(c.back() == 3);
+    i = 4;
+    assert(c.size() == 2);
+    assert(c.back() == 4);
+    return true;
 }
 
 int main(int, char**)
 {
     test(std::vector<int>());
     test(nasty_vector<int>());
-
-  return 0;
+#if TEST_STD_VER >= 20
+    test(ConstexprFixedCapacityDeque<int, 10>());
+    static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
+#endif
+    return 0;
 }

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp
index ccdb444f11b39..c96b8527bef0a 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.insert.iter.cons/container.pass.cpp
@@ -10,7 +10,7 @@
 
 // front_insert_iterator
 
-// explicit front_insert_iterator(Cont& x);
+// explicit front_insert_iterator(Cont& x); // constexpr in C++20
 
 #include <iterator>
 #include <list>

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.inserter/test.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.inserter/test.pass.cpp
index f27178941936c..9718f8c93323e 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.inserter/test.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/front.insert.iter.ops/front.inserter/test.pass.cpp
@@ -8,9 +8,9 @@
 
 // <iterator>
 
-// template <BackInsertionContainer Cont>
+// template <FrontInsertionContainer Cont>
 //   front_insert_iterator<Cont>
-//   front_inserter(Cont& x);
+//   front_inserter(Cont& x); // constexpr in C++20
 
 #include <cassert>
 #include <iterator>
@@ -25,9 +25,12 @@ TEST_CONSTEXPR_CXX20 bool
 test(C c)
 {
     std::front_insert_iterator<C> i = std::front_inserter(c);
-    i = 0;
+    i = 3;
     assert(c.size() == 1);
-    assert(c.front() == 0);
+    assert(c.front() == 3);
+    i = 4;
+    assert(c.size() == 2);
+    assert(c.front() == 4);
     return true;
 }
 

diff  --git a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/test.pass.cpp b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/test.pass.cpp
index 8def436a0cc91..af2e85471ae4e 100644
--- a/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/test.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.cons/test.pass.cpp
@@ -10,7 +10,7 @@
 
 // insert_iterator
 
-// insert_iterator(Cont& x, Cont::iterator i);
+// insert_iterator(Cont& x, Cont::iterator i); // constexpr in C++20
 
 #include <iterator>
 #include <vector>

diff  --git a/libcxx/test/support/nasty_containers.h b/libcxx/test/support/nasty_containers.h
index 91251666ba734..0b56a27feefa2 100644
--- a/libcxx/test/support/nasty_containers.h
+++ b/libcxx/test/support/nasty_containers.h
@@ -206,7 +206,7 @@ class nasty_list
     void push_back(const value_type& x)     { l_.push_back(x); }
 #if TEST_STD_VER >= 11
     void push_back(value_type&& x)          { l_.push_back(std::forward<value_type&&>(x)); }
-    void push_front(value_type&& x)         { l_.push_back(std::forward<value_type&&>(x)); }
+    void push_front(value_type&& x)         { l_.push_front(std::forward<value_type&&>(x)); }
     template <class... Args>
         void emplace_back(Args&&... args)   { l_.emplace_back(std::forward<Args>(args)...); }
     template <class... Args>
@@ -234,10 +234,10 @@ class nasty_list
 #endif
 
     iterator erase(const_iterator pos)                      { return l_.erase(pos); }
-    iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
+    iterator erase(const_iterator first, const_iterator last) { return l_.erase(first, last); }
 
-    void resize(size_type)                      { l_.resize(); }
-    void resize(size_type, const value_type& c) { l_.resize(c); }
+    void resize(size_type n)                      { l_.resize(n); }
+    void resize(size_type n, const value_type& c) { l_.resize(n, c); }
 
     void swap(nasty_list &nl)
 #if TEST_STD_VER > 14


        


More information about the libcxx-commits mailing list