[libcxx-commits] [libcxx] ff94bd1 - [libcxx][test][NFC] noexcept tests for std::array

Ruslan Arutyunyan via libcxx-commits libcxx-commits at lists.llvm.org
Sat Dec 18 05:14:38 PST 2021


Author: Konstantin Boyarinov
Date: 2021-12-18T16:06:56+03:00
New Revision: ff94bd1bc92efb2a116fb2963d0425a529d3be89

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

LOG: [libcxx][test][NFC] noexcept tests for std::array

Minor change - add tests that std::array methods (data, (c/r)begin,
(c/r)end) are noexcept

Reviewed By: ldionne, rarutyun, #libc

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

Added: 
    

Modified: 
    libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp
    libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp
    libcxx/test/std/containers/sequences/array/iterators.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp
index 4e8b1ab9789ff..ed2d814d37fed 100644
--- a/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp
@@ -35,6 +35,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef double T;
         typedef std::array<T, 3> C;
         C c = {1, 2, 3.5};
+        ASSERT_NOEXCEPT(c.data());
         T* p = c.data();
         assert(p[0] == 1);
         assert(p[1] == 2);
@@ -44,6 +45,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef double T;
         typedef std::array<T, 0> C;
         C c = {};
+        ASSERT_NOEXCEPT(c.data());
         T* p = c.data();
         (void)p;
     }
@@ -51,6 +53,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef double T;
         typedef std::array<const T, 0> C;
         C c = {{}};
+        ASSERT_NOEXCEPT(c.data());
         const T* p = c.data();
         (void)p;
         static_assert((std::is_same<decltype(c.data()), const T*>::value), "");
@@ -59,6 +62,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef NoDefault T;
         typedef std::array<T, 0> C;
         C c = {};
+        ASSERT_NOEXCEPT(c.data());
         T* p = c.data();
         (void)p;
     }

diff  --git a/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp
index cc180793b177e..d9336e3fef374 100644
--- a/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp
@@ -35,6 +35,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef double T;
         typedef std::array<T, 3> C;
         const C c = {1, 2, 3.5};
+        ASSERT_NOEXCEPT(c.data());
         const T* p = c.data();
         assert(p[0] == 1);
         assert(p[1] == 2);
@@ -44,6 +45,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef double T;
         typedef std::array<T, 0> C;
         const C c = {};
+        ASSERT_NOEXCEPT(c.data());
         const T* p = c.data();
         (void)p;
     }
@@ -51,6 +53,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
         typedef NoDefault T;
         typedef std::array<T, 0> C;
         const C c = {};
+        ASSERT_NOEXCEPT(c.data());
         const T* p = c.data();
         (void)p;
     }

diff  --git a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp
index 8d15cf861c3c5..106bc45c70998 100644
--- a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp
@@ -33,11 +33,30 @@ struct NoDefault {
     TEST_CONSTEXPR NoDefault(int) { }
 };
 
+template <class T>
+TEST_CONSTEXPR_CXX17 void check_noexcept(T& c) {
+    ASSERT_NOEXCEPT(c.begin());
+    ASSERT_NOEXCEPT(c.end());
+    ASSERT_NOEXCEPT(c.cbegin());
+    ASSERT_NOEXCEPT(c.cend());
+    ASSERT_NOEXCEPT(c.rbegin());
+    ASSERT_NOEXCEPT(c.rend());
+    ASSERT_NOEXCEPT(c.crbegin());
+    ASSERT_NOEXCEPT(c.crend());
+
+    const T& cc = c; (void)cc;
+    ASSERT_NOEXCEPT(cc.begin());
+    ASSERT_NOEXCEPT(cc.end());
+    ASSERT_NOEXCEPT(cc.rbegin());
+    ASSERT_NOEXCEPT(cc.rend());
+}
+
 TEST_CONSTEXPR_CXX17 bool tests()
 {
     {
         typedef std::array<int, 5> C;
         C array = {};
+        check_noexcept(array);
         typename C::iterator i = array.begin();
         typename C::const_iterator j = array.cbegin();
         assert(i == j);
@@ -45,6 +64,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
     {
         typedef std::array<int, 0> C;
         C array = {};
+        check_noexcept(array);
         typename C::iterator i = array.begin();
         typename C::const_iterator j = array.cbegin();
         assert(i == j);
@@ -53,6 +73,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
     {
         typedef std::array<int, 0> C;
         C array = {};
+        check_noexcept(array);
         typename C::iterator i = array.begin();
         typename C::const_iterator j = array.cbegin();
         assert(i == array.end());
@@ -61,6 +82,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
     {
         typedef std::array<int, 1> C;
         C array = {1};
+        check_noexcept(array);
         typename C::iterator i = array.begin();
         assert(*i == 1);
         assert(&*i == array.data());
@@ -70,6 +92,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
     {
         typedef std::array<int, 2> C;
         C array = {1, 2};
+        check_noexcept(array);
         typename C::iterator i = array.begin();
         assert(*i == 1);
         assert(&*i == array.data());
@@ -80,6 +103,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
     {
         typedef std::array<double, 3> C;
         C array = {1, 2, 3.5};
+        check_noexcept(array);
         typename C::iterator i = array.begin();
         assert(*i == 1);
         assert(&*i == array.data());
@@ -110,6 +134,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
             assert(!(ii1 != cii));
 
             C c = {};
+            check_noexcept(c);
             assert(c.begin()   == std::begin(c));
             assert(c.cbegin()  == std::cbegin(c));
             assert(c.rbegin()  == std::rbegin(c));
@@ -150,6 +175,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
             assert(ii1 - cii == 0);
 
             C c = {};
+            check_noexcept(c);
             assert(c.begin()   == std::begin(c));
             assert(c.cbegin()  == std::cbegin(c));
             assert(c.rbegin()  == std::rbegin(c));


        


More information about the libcxx-commits mailing list