[libc++] Complete overhaul of constexpr support in std::array
This commit adds missing support for constexpr in std::array under all
standard modes up to and including C++20. It also transforms the <array>
tests to check for constexpr-friendliness under the right standard modes.
Fixes https://llvm.org/PR40124
Fixes rdar://57522096
Supersedes https://reviews.llvm.org/D60666
Differential Revision: https://reviews.llvm.org/D80452
diff --git a/libcxx/test/std/containers/sequences/array/aggregate.pass.cpp b/libcxx/test/std/containers/sequences/array/aggregate.pass.cpp
new file mode 100644
index 0000000..dd4064b
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/array/aggregate.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Make sure std::array is an aggregate type.
+
+#include <array>
+#include <type_traits>
+
+template <typename T>
+void tests()
+{
+ // Test aggregate initialization
+ {
+ std::array<T, 0> a0 = {}; (void)a0;
+ std::array<T, 1> a1 = {T()}; (void)a1;
+ std::array<T, 2> a2 = {T(), T()}; (void)a2;
+ std::array<T, 3> a3 = {T(), T(), T()}; (void)a3;
+ }
+
+ // Test the is_aggregate trait.
+#if TEST_STD_VER >= 17 // The trait is only available in C++17 and above
+ static_assert(std::is_aggregate<std::array<T, 0> >::value, "");
+ static_assert(std::is_aggregate<std::array<T, 1> >::value, "");
+ static_assert(std::is_aggregate<std::array<T, 2> >::value, "");
+ static_assert(std::is_aggregate<std::array<T, 3> >::value, "");
+ static_assert(std::is_aggregate<std::array<T, 4> >::value, "");
+#endif
+}
+
+struct Empty { };
+struct NonEmpty { int i; int j; };
+
+int main(int, char**)
+{
+ tests<char>();
+ tests<int>();
+ tests<long>();
+ tests<float>();
+ tests<double>();
+ tests<long double>();
+ tests<NonEmpty>();
+ tests<Empty>();
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/array/array.cons/deduct.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/deduct.pass.cpp
index 141aafc..42ebef6 100644
--- a/libcxx/test/std/containers/sequences/array/array.cons/deduct.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.cons/deduct.pass.cpp
@@ -30,37 +30,44 @@
#include "test_macros.h"
+constexpr bool tests()
+{
+ // Test the explicit deduction guides
+ {
+ std::array arr{1,2,3}; // array(T, U...)
+ static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
+ assert(arr[0] == 1);
+ assert(arr[1] == 2);
+ assert(arr[2] == 3);
+ }
+
+ {
+ const long l1 = 42;
+ std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
+ static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
+ static_assert(arr.size() == 4, "");
+ assert(arr[0] == 1);
+ assert(arr[1] == 4);
+ assert(arr[2] == 9);
+ assert(arr[3] == l1);
+ }
+
+ // Test the implicit deduction guides
+ {
+ std::array<double, 2> source = {4.0, 5.0};
+ std::array arr(source); // array(array)
+ static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
+ static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
+ assert(arr[0] == 4.0);
+ assert(arr[1] == 5.0);
+ }
+
+ return true;
+}
+
int main(int, char**)
{
-// Test the explicit deduction guides
- {
- std::array arr{1,2,3}; // array(T, U...)
- static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, "");
- assert(arr[0] == 1);
- assert(arr[1] == 2);
- assert(arr[2] == 3);
- }
-
- {
- const long l1 = 42;
- std::array arr{1L, 4L, 9L, l1}; // array(T, U...)
- static_assert(std::is_same_v<decltype(arr)::value_type, long>, "");
- static_assert(arr.size() == 4, "");
- assert(arr[0] == 1);
- assert(arr[1] == 4);
- assert(arr[2] == 9);
- assert(arr[3] == l1);
- }
-
-// Test the implicit deduction guides
- {
- std::array<double, 2> source = {4.0, 5.0};
- std::array arr(source); // array(array)
- static_assert(std::is_same_v<decltype(arr), decltype(source)>, "");
- static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, "");
- assert(arr[0] == 4.0);
- assert(arr[1] == 5.0);
- }
-
- return 0;
+ tests();
+ static_assert(tests(), "");
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp
index 16671e3..e73a967 100644
--- a/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp
@@ -19,32 +19,43 @@
#include "disable_missing_braces_warning.h"
struct NoDefault {
- NoDefault(int) {}
+ TEST_CONSTEXPR NoDefault(int) { }
};
+struct Default {
+ TEST_CONSTEXPR Default() { }
+};
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ std::array<Default, 3> array;
+ assert(array.size() == 3);
+ }
+
+ {
+ std::array<Default, 0> array;
+ assert(array.size() == 0);
+ }
+
+ {
+ typedef std::array<NoDefault, 0> C;
+ C c;
+ assert(c.size() == 0);
+ C c1 = {};
+ assert(c1.size() == 0);
+ C c2 = {{}};
+ assert(c2.size() == 0);
+ }
+
+ return true;
+}
+
int main(int, char**)
{
- {
- typedef double T;
- typedef std::array<T, 3> C;
- C c;
- assert(c.size() == 3);
- }
- {
- typedef double T;
- typedef std::array<T, 0> C;
- C c;
- assert(c.size() == 0);
- }
- {
- typedef std::array<NoDefault, 0> C;
- C c;
- assert(c.size() == 0);
- C c1 = {};
- assert(c1.size() == 0);
- C c2 = {{}};
- assert(c2.size() == 0);
- }
-
- return 0;
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.cons/implicit_copy.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/implicit_copy.pass.cpp
index c0e205c..cb9a18298 100644
--- a/libcxx/test/std/containers/sequences/array/array.cons/implicit_copy.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.cons/implicit_copy.pass.cpp
@@ -23,72 +23,81 @@
// generated operator would be ill-formed; like in the case of a struct with a
// const member.
#if TEST_STD_VER < 11
-#define TEST_NOT_COPY_ASSIGNABLE(T) ((void)0)
+# define TEST_NOT_COPY_ASSIGNABLE(T) ((void)0)
#else
-#define TEST_NOT_COPY_ASSIGNABLE(T) static_assert(!std::is_copy_assignable<T>::value, "")
+# define TEST_NOT_COPY_ASSIGNABLE(T) static_assert(!std::is_copy_assignable<T>::value, "")
#endif
struct NoDefault {
- NoDefault(int) {}
+ TEST_CONSTEXPR NoDefault(int) { }
};
-int main(int, char**) {
- {
- typedef double T;
- typedef std::array<T, 3> C;
- C c = {1.1, 2.2, 3.3};
- C c2 = c;
- c2 = c;
- static_assert(std::is_copy_constructible<C>::value, "");
- static_assert(std::is_copy_assignable<C>::value, "");
- }
- {
- typedef double T;
- typedef std::array<const T, 3> C;
- C c = {1.1, 2.2, 3.3};
- C c2 = c;
- ((void)c2);
- static_assert(std::is_copy_constructible<C>::value, "");
- TEST_NOT_COPY_ASSIGNABLE(C);
- }
- {
- typedef double T;
- typedef std::array<T, 0> C;
- C c = {};
- C c2 = c;
- c2 = c;
- static_assert(std::is_copy_constructible<C>::value, "");
- static_assert(std::is_copy_assignable<C>::value, "");
- }
- {
- // const arrays of size 0 should disable the implicit copy assignment operator.
- typedef double T;
- typedef std::array<const T, 0> C;
- C c = {{}};
- C c2 = c;
- ((void)c2);
- static_assert(std::is_copy_constructible<C>::value, "");
- TEST_NOT_COPY_ASSIGNABLE(C);
- }
- {
- typedef NoDefault T;
- typedef std::array<T, 0> C;
- C c = {};
- C c2 = c;
- c2 = c;
- static_assert(std::is_copy_constructible<C>::value, "");
- static_assert(std::is_copy_assignable<C>::value, "");
- }
- {
- typedef NoDefault T;
- typedef std::array<const T, 0> C;
- C c = {{}};
- C c2 = c;
- ((void)c2);
- static_assert(std::is_copy_constructible<C>::value, "");
- TEST_NOT_COPY_ASSIGNABLE(C);
- }
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef double T;
+ typedef std::array<T, 3> C;
+ C c = {1.1, 2.2, 3.3};
+ C c2 = c;
+ c2 = c;
+ static_assert(std::is_copy_constructible<C>::value, "");
+ static_assert(std::is_copy_assignable<C>::value, "");
+ }
+ {
+ typedef double T;
+ typedef std::array<const T, 3> C;
+ C c = {1.1, 2.2, 3.3};
+ C c2 = c;
+ ((void)c2);
+ static_assert(std::is_copy_constructible<C>::value, "");
+ TEST_NOT_COPY_ASSIGNABLE(C);
+ }
+ {
+ typedef double T;
+ typedef std::array<T, 0> C;
+ C c = {};
+ C c2 = c;
+ c2 = c;
+ static_assert(std::is_copy_constructible<C>::value, "");
+ static_assert(std::is_copy_assignable<C>::value, "");
+ }
+ {
+ // const arrays of size 0 should disable the implicit copy assignment operator.
+ typedef double T;
+ typedef std::array<const T, 0> C;
+ C c = {{}};
+ C c2 = c;
+ ((void)c2);
+ static_assert(std::is_copy_constructible<C>::value, "");
+ TEST_NOT_COPY_ASSIGNABLE(C);
+ }
+ {
+ typedef NoDefault T;
+ typedef std::array<T, 0> C;
+ C c = {};
+ C c2 = c;
+ c2 = c;
+ static_assert(std::is_copy_constructible<C>::value, "");
+ static_assert(std::is_copy_assignable<C>::value, "");
+ }
+ {
+ typedef NoDefault T;
+ typedef std::array<const T, 0> C;
+ C c = {{}};
+ C c2 = c;
+ ((void)c2);
+ static_assert(std::is_copy_constructible<C>::value, "");
+ TEST_NOT_COPY_ASSIGNABLE(C);
+ }
+ return true;
+}
- return 0;
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp
index cdc04b1..4943754 100644
--- a/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp
@@ -18,12 +18,12 @@
#include "test_macros.h"
#include "disable_missing_braces_warning.h"
-int main(int, char**)
+TEST_CONSTEXPR_CXX14 bool tests()
{
{
typedef double T;
typedef std::array<T, 3> C;
- C c = {1, 2, 3.5};
+ C const c = {1, 2, 3.5};
assert(c.size() == 3);
assert(c[0] == 1);
assert(c[1] == 2);
@@ -32,23 +32,32 @@
{
typedef double T;
typedef std::array<T, 0> C;
- C c = {};
+ C const c = {};
assert(c.size() == 0);
}
{
typedef double T;
typedef std::array<T, 3> C;
- C c = {1};
+ C const c = {1};
assert(c.size() == 3.0);
assert(c[0] == 1);
}
{
typedef int T;
typedef std::array<T, 1> C;
- C c = {};
+ C const c = {};
assert(c.size() == 1);
}
- return 0;
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.creation/to_array.pass.cpp b/libcxx/test/std/containers/sequences/array/array.creation/to_array.pass.cpp
index d5df96a..8716549 100644
--- a/libcxx/test/std/containers/sequences/array/array.creation/to_array.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.creation/to_array.pass.cpp
@@ -23,7 +23,8 @@
#include "test_macros.h"
#include "MoveOnly.h"
-int main(int, char**) {
+constexpr bool tests()
+{
// Test deduced type.
{
auto arr = std::to_array({1, 2, 3});
@@ -110,13 +111,12 @@
assert(arr[0].b == .1);
}
- // Test constexpr.
- {
- constexpr std::array<int, 3> arr = std::to_array({1, 2, 3});
- static_assert(arr[0] == 1);
- static_assert(arr[1] == 2);
- static_assert(arr[2] == 3);
- }
+ return true;
+}
+int main(int, char**)
+{
+ tests();
+ static_assert(tests(), "");
return 0;
}
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 434cbc5..a41409f 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
@@ -21,7 +21,7 @@
#include "disable_missing_braces_warning.h"
struct NoDefault {
- NoDefault(int) {}
+ TEST_CONSTEXPR NoDefault(int) { }
};
#if TEST_STD_VER < 11
@@ -33,7 +33,7 @@
};
#endif
-int main(int, char**)
+TEST_CONSTEXPR_CXX17 bool tests()
{
{
typedef double T;
@@ -52,33 +52,49 @@
LIBCPP_ASSERT(p != nullptr);
}
{
- typedef double T;
- typedef std::array<const T, 0> C;
- C c = {{}};
- const T* p = c.data();
- static_assert((std::is_same<decltype(c.data()), const T*>::value), "");
- LIBCPP_ASSERT(p != nullptr);
- }
- {
-#if TEST_STD_VER < 11
- typedef natural_alignment T;
-#else
- typedef std::max_align_t T;
-#endif
- typedef std::array<T, 0> C;
- const C c = {};
- const T* p = c.data();
- LIBCPP_ASSERT(p != nullptr);
- std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
- assert(pint % TEST_ALIGNOF(T) == 0);
+ typedef double T;
+ typedef std::array<const T, 0> C;
+ C c = {{}};
+ const T* p = c.data();
+ LIBCPP_ASSERT(p != nullptr);
+ static_assert((std::is_same<decltype(c.data()), const T*>::value), "");
}
{
- typedef NoDefault T;
- typedef std::array<T, 0> C;
- C c = {};
- T* p = c.data();
- LIBCPP_ASSERT(p != nullptr);
+ typedef NoDefault T;
+ typedef std::array<T, 0> C;
+ C c = {};
+ T* p = c.data();
+ LIBCPP_ASSERT(p != nullptr);
+ }
+ {
+ std::array<int, 5> c = {0, 1, 2, 3, 4};
+ assert(c.data() == &c[0]);
+ assert(*c.data() == c[0]);
}
- return 0;
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 17
+ static_assert(tests(), "");
+#endif
+
+ // Test the alignment of data()
+ {
+#if TEST_STD_VER < 11
+ typedef natural_alignment T;
+#else
+ typedef std::max_align_t T;
+#endif
+ typedef std::array<T, 0> C;
+ const C c = {};
+ const T* p = c.data();
+ LIBCPP_ASSERT(p != nullptr);
+ std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
+ assert(pint % TEST_ALIGNOF(T) == 0);
+ }
+ return 0;
}
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 92828ee..0f79237 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
@@ -21,7 +21,7 @@
#include "disable_missing_braces_warning.h"
struct NoDefault {
- NoDefault(int) {}
+ TEST_CONSTEXPR NoDefault(int) { }
};
#if TEST_STD_VER < 11
@@ -33,7 +33,7 @@
};
#endif
-int main(int, char**)
+TEST_CONSTEXPR_CXX17 bool tests()
{
{
typedef double T;
@@ -49,40 +49,45 @@
typedef std::array<T, 0> C;
const C c = {};
const T* p = c.data();
- (void)p; // to placate scan-build
+ LIBCPP_ASSERT(p != nullptr);
}
{
- typedef NoDefault T;
- typedef std::array<T, 0> C;
- const C c = {};
- const T* p = c.data();
- LIBCPP_ASSERT(p != nullptr);
+ typedef NoDefault T;
+ typedef std::array<T, 0> C;
+ const C c = {};
+ const T* p = c.data();
+ LIBCPP_ASSERT(p != nullptr);
}
{
+ std::array<int, 5> const c = {0, 1, 2, 3, 4};
+ assert(c.data() == &c[0]);
+ assert(*c.data() == c[0]);
+ }
+
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 17
+ static_assert(tests(), "");
+#endif
+
+ // Test the alignment of data()
+ {
#if TEST_STD_VER < 11
- typedef natural_alignment T;
+ typedef natural_alignment T;
#else
- typedef std::max_align_t T;
+ typedef std::max_align_t T;
#endif
- typedef std::array<T, 0> C;
- const C c = {};
- const T* p = c.data();
- LIBCPP_ASSERT(p != nullptr);
- std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
- assert(pint % TEST_ALIGNOF(T) == 0);
+ typedef std::array<T, 0> C;
+ const C c = {};
+ const T* p = c.data();
+ LIBCPP_ASSERT(p != nullptr);
+ std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
+ assert(pint % TEST_ALIGNOF(T) == 0);
}
-#if TEST_STD_VER > 14
- {
- typedef std::array<int, 5> C;
- constexpr C c1{0,1,2,3,4};
- constexpr const C c2{0,1,2,3,4};
- static_assert ( c1.data() == &c1[0], "");
- static_assert ( *c1.data() == c1[0], "");
- static_assert ( c2.data() == &c2[0], "");
- static_assert ( *c2.data() == c2[0], "");
- }
-#endif
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp b/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp
index f480d17..3a185110 100644
--- a/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp
@@ -18,7 +18,7 @@
#include "test_macros.h"
#include "disable_missing_braces_warning.h"
-int main(int, char**)
+TEST_CONSTEXPR_CXX20 bool tests()
{
{
typedef double T;
@@ -30,6 +30,7 @@
assert(c[1] == 5.5);
assert(c[2] == 5.5);
}
+
{
typedef double T;
typedef std::array<T, 0> C;
@@ -37,6 +38,14 @@
c.fill(5.5);
assert(c.size() == 0);
}
+ return true;
+}
- return 0;
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 20
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp b/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp
index f837bdc..e550300 100644
--- a/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp
@@ -56,5 +56,5 @@
}
#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
index 6c9ed95..788f0ed 100644
--- a/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
@@ -19,10 +19,10 @@
#include "disable_missing_braces_warning.h"
struct NonSwappable {
- NonSwappable() {}
+ TEST_CONSTEXPR NonSwappable() { }
private:
- NonSwappable(NonSwappable const&);
- NonSwappable& operator=(NonSwappable const&);
+ NonSwappable(NonSwappable const&);
+ NonSwappable& operator=(NonSwappable const&);
};
template <class Tp>
@@ -33,9 +33,9 @@
std::false_type can_swap_imp(...);
template <class Tp>
-struct can_swap : std::is_same<decltype(can_swap_imp<Tp>(0)), void> {};
+struct can_swap : std::is_same<decltype(can_swap_imp<Tp>(0)), void> { };
-int main(int, char**)
+TEST_CONSTEXPR_CXX20 bool tests()
{
{
typedef double T;
@@ -82,5 +82,14 @@
}
#endif
- return 0;
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 20
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp
index aac8a13..1f2d8e7 100644
--- a/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp
@@ -21,13 +21,13 @@
#include "disable_missing_braces_warning.h"
struct NonSwappable {
- NonSwappable() {}
+ TEST_CONSTEXPR NonSwappable() { }
private:
- NonSwappable(NonSwappable const&);
- NonSwappable& operator=(NonSwappable const&);
+ NonSwappable(NonSwappable const&);
+ NonSwappable& operator=(NonSwappable const&);
};
-int main(int, char**)
+TEST_CONSTEXPR_CXX20 bool tests()
{
{
typedef double T;
@@ -89,6 +89,14 @@
#endif
}
+ return true;
+}
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 20
+ static_assert(tests(), "");
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
index 9e94417..1b13d77 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
@@ -20,41 +20,57 @@
#include "disable_missing_braces_warning.h"
-#if TEST_STD_VER > 11
-struct S {
- std::array<int, 3> a;
- int k;
- constexpr S() : a{1,2,3}, k(std::get<2>(a)) {}
-};
+template <typename ...T>
+TEST_CONSTEXPR std::array<int, sizeof...(T)> tempArray(T ...args)
+{
+ return {args...};
+}
-constexpr std::array<int, 2> getArr () { return { 3, 4 }; }
-#endif
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ std::array<double, 1> array = {3.3};
+ assert(std::get<0>(array) == 3.3);
+ std::get<0>(array) = 99.1;
+ assert(std::get<0>(array) == 99.1);
+ }
+ {
+ std::array<double, 2> array = {3.3, 4.4};
+ assert(std::get<0>(array) == 3.3);
+ assert(std::get<1>(array) == 4.4);
+ std::get<0>(array) = 99.1;
+ std::get<1>(array) = 99.2;
+ assert(std::get<0>(array) == 99.1);
+ assert(std::get<1>(array) == 99.2);
+ }
+ {
+ std::array<double, 3> array = {3.3, 4.4, 5.5};
+ assert(std::get<0>(array) == 3.3);
+ assert(std::get<1>(array) == 4.4);
+ assert(std::get<2>(array) == 5.5);
+ std::get<1>(array) = 99.2;
+ assert(std::get<0>(array) == 3.3);
+ assert(std::get<1>(array) == 99.2);
+ assert(std::get<2>(array) == 5.5);
+ }
+ {
+ std::array<double, 1> array = {3.3};
+ static_assert(std::is_same<double&, decltype(std::get<0>(array))>::value, "");
+ }
+ {
+ assert(std::get<0>(tempArray(1, 2, 3)) == 1);
+ assert(std::get<1>(tempArray(1, 2, 3)) == 2);
+ assert(std::get<2>(tempArray(1, 2, 3)) == 3);
+ }
+
+ return true;
+}
int main(int, char**)
{
- {
- typedef double T;
- typedef std::array<T, 3> C;
- C c = {1, 2, 3.5};
- std::get<1>(c) = 5.5;
- assert(c[0] == 1);
- assert(c[1] == 5.5);
- assert(c[2] == 3.5);
- }
-#if TEST_STD_VER > 11
- {
- typedef double T;
- typedef std::array<T, 3> C;
- constexpr C c = {1, 2, 3.5};
- static_assert(std::get<0>(c) == 1, "");
- static_assert(std::get<1>(c) == 2, "");
- static_assert(std::get<2>(c) == 3.5, "");
- }
- {
- static_assert(S().k == 3, "");
- static_assert(std::get<1>(getArr()) == 4, "");
- }
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
#endif
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp
index b22a761..3c1941c 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp
@@ -19,26 +19,36 @@
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
-int main(int, char**)
+TEST_CONSTEXPR_CXX14 bool tests()
{
{
- typedef double T;
- typedef std::array<T, 3> C;
- const C c = {1, 2, 3.5};
- assert(std::get<0>(c) == 1);
- assert(std::get<1>(c) == 2);
- assert(std::get<2>(c) == 3.5);
+ std::array<double, 1> const array = {3.3};
+ assert(std::get<0>(array) == 3.3);
}
-#if TEST_STD_VER > 11
{
- typedef double T;
- typedef std::array<T, 3> C;
- constexpr const C c = {1, 2, 3.5};
- static_assert(std::get<0>(c) == 1, "");
- static_assert(std::get<1>(c) == 2, "");
- static_assert(std::get<2>(c) == 3.5, "");
+ std::array<double, 2> const array = {3.3, 4.4};
+ assert(std::get<0>(array) == 3.3);
+ assert(std::get<1>(array) == 4.4);
}
-#endif
+ {
+ std::array<double, 3> const array = {3.3, 4.4, 5.5};
+ assert(std::get<0>(array) == 3.3);
+ assert(std::get<1>(array) == 4.4);
+ assert(std::get<2>(array) == 5.5);
+ }
+ {
+ std::array<double, 1> const array = {3.3};
+ static_assert(std::is_same<double const&, decltype(std::get<0>(array))>::value, "");
+ }
- return 0;
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
index ce8fc4f..3469780 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
@@ -28,25 +28,25 @@
{
{
- typedef std::unique_ptr<double> T;
- typedef std::array<T, 1> C;
- const C c = {std::unique_ptr<double>(new double(3.5))};
- static_assert(std::is_same<const T&&, decltype(std::get<0>(std::move(c)))>::value, "");
- static_assert(noexcept(std::get<0>(std::move(c))), "");
- const T&& t = std::get<0>(std::move(c));
- assert(*t == 3.5);
+ typedef std::unique_ptr<double> T;
+ typedef std::array<T, 1> C;
+ const C c = {std::unique_ptr<double>(new double(3.5))};
+ static_assert(std::is_same<const T&&, decltype(std::get<0>(std::move(c)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(c))), "");
+ const T&& t = std::get<0>(std::move(c));
+ assert(*t == 3.5);
}
-#if TEST_STD_VER > 11
+#if TEST_STD_VER >= 14
{
- typedef double T;
- typedef std::array<T, 3> C;
- constexpr const C c = {1, 2, 3.5};
- static_assert(std::get<0>(std::move(c)) == 1, "");
- static_assert(std::get<1>(std::move(c)) == 2, "");
- static_assert(std::get<2>(std::move(c)) == 3.5, "");
+ typedef double T;
+ typedef std::array<T, 3> C;
+ constexpr const C c = {1, 2, 3.5};
+ static_assert(std::get<0>(std::move(c)) == 1, "");
+ static_assert(std::get<1>(std::move(c)) == 2, "");
+ static_assert(std::get<2>(std::move(c)) == 3.5, "");
}
#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp
index d1d8b28..e557c19 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp
@@ -33,5 +33,5 @@
assert(*t == 3.5);
}
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
index a4fbd3a..cde4ba7 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
@@ -18,7 +18,6 @@
#include <array>
#include <cassert>
-
// std::array is explicitly allowed to be initialized with A a = { init-list };.
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
diff --git a/libcxx/test/std/containers/sequences/array/at.pass.cpp b/libcxx/test/std/containers/sequences/array/at.pass.cpp
index 0454643..ed4ab80 100644
--- a/libcxx/test/std/containers/sequences/array/at.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/at.pass.cpp
@@ -8,10 +8,7 @@
// <array>
-// reference operator[] (size_type)
-// const_reference operator[] (size_type); // constexpr in C++14
-// reference at (size_type)
-// const_reference at (size_type); // constexpr in C++14
+// reference at (size_type); // constexpr in C++17
#include <array>
#include <cassert>
@@ -26,100 +23,91 @@
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
-#if TEST_STD_VER > 14
-constexpr bool check_idx( size_t idx, double val )
-{
- std::array<double, 3> arr = {1, 2, 3.5};
- return arr.at(idx) == val;
-}
-#endif
-int main(int, char**)
+TEST_CONSTEXPR_CXX17 bool tests()
{
{
typedef double T;
typedef std::array<T, 3> C;
C c = {1, 2, 3.5};
- C::reference r1 = c.at(0);
+ typename C::reference r1 = c.at(0);
assert(r1 == 1);
r1 = 5.5;
- assert(c.front() == 5.5);
+ assert(c[0] == 5.5);
- C::reference r2 = c.at(2);
+ typename C::reference r2 = c.at(2);
assert(r2 == 3.5);
r2 = 7.5;
- assert(c.back() == 7.5);
-
-#ifndef TEST_HAS_NO_EXCEPTIONS
- try
- {
- TEST_IGNORE_NODISCARD c.at(3);
- assert(false);
- }
- catch (const std::out_of_range &) {}
-#endif
+ assert(c[2] == 7.5);
}
+ return true;
+}
+
+void test_exceptions()
+{
#ifndef TEST_HAS_NO_EXCEPTIONS
{
- typedef double T;
- typedef std::array<T, 0> C;
- C c = {};
- C const& cc = c;
- try
- {
- TEST_IGNORE_NODISCARD c.at(0);
+ std::array<int, 4> array = {1, 2, 3, 4};
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(4);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
assert(false);
}
- catch (const std::out_of_range &) {}
- try
- {
- TEST_IGNORE_NODISCARD cc.at(0);
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(5);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
assert(false);
}
- catch (const std::out_of_range &) {}
- }
-#endif
- {
- typedef double T;
- typedef std::array<T, 3> C;
- const C c = {1, 2, 3.5};
- C::const_reference r1 = c.at(0);
- assert(r1 == 1);
- C::const_reference r2 = c.at(2);
- assert(r2 == 3.5);
-
-#ifndef TEST_HAS_NO_EXCEPTIONS
- try
- {
- TEST_IGNORE_NODISCARD c.at(3);
+ try {
+ TEST_IGNORE_NODISCARD array.at(6);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
assert(false);
}
- catch (const std::out_of_range &) {}
-#endif
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(-1);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
}
-#if TEST_STD_VER > 11
{
- typedef double T;
- typedef std::array<T, 3> C;
- constexpr C c = {1, 2, 3.5};
+ std::array<int, 0> array = {};
- constexpr T t1 = c.at(0);
- static_assert (t1 == 1, "");
-
- constexpr T t2 = c.at(2);
- static_assert (t2 == 3.5, "");
+ try {
+ TEST_IGNORE_NODISCARD array.at(0);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
}
#endif
+}
-#if TEST_STD_VER > 14
- {
- static_assert (check_idx(0, 1), "");
- static_assert (check_idx(1, 2), "");
- static_assert (check_idx(2, 3.5), "");
- }
+int main(int, char**)
+{
+ tests();
+ test_exceptions();
+
+#if TEST_STD_VER >= 17
+ static_assert(tests(), "");
#endif
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/at_const.pass.cpp b/libcxx/test/std/containers/sequences/array/at_const.pass.cpp
new file mode 100644
index 0000000..d79c505
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/array/at_const.pass.cpp
@@ -0,0 +1,109 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <array>
+
+// const_reference at (size_type) const; // constexpr in C++14
+
+#include <array>
+#include <cassert>
+
+#ifndef TEST_HAS_NO_EXCEPTIONS
+#include <stdexcept>
+#endif
+
+#include "test_macros.h"
+
+// std::array is explicitly allowed to be initialized with A a = { init-list };.
+// Disable the missing braces warning for this reason.
+#include "disable_missing_braces_warning.h"
+
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef double T;
+ typedef std::array<T, 3> C;
+ C const c = {1, 2, 3.5};
+ typename C::const_reference r1 = c.at(0);
+ assert(r1 == 1);
+
+ typename C::const_reference r2 = c.at(2);
+ assert(r2 == 3.5);
+ }
+ return true;
+}
+
+void test_exceptions()
+{
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ {
+ std::array<int, 4> const array = {1, 2, 3, 4};
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(4);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(5);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(6);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(-1);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
+ }
+
+ {
+ std::array<int, 0> array = {};
+
+ try {
+ TEST_IGNORE_NODISCARD array.at(0);
+ assert(false);
+ } catch (std::out_of_range const&) {
+ // pass
+ } catch (...) {
+ assert(false);
+ }
+ }
+#endif
+}
+
+int main(int, char**)
+{
+ tests();
+ test_exceptions();
+
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/array/begin.pass.cpp b/libcxx/test/std/containers/sequences/array/begin.pass.cpp
deleted file mode 100644
index 7b26d23..0000000
--- a/libcxx/test/std/containers/sequences/array/begin.pass.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-// <array>
-
-// iterator begin();
-
-#include <array>
-#include <cassert>
-
-#include "test_macros.h"
-
-// std::array is explicitly allowed to be initialized with A a = { init-list };.
-// Disable the missing braces warning for this reason.
-#include "disable_missing_braces_warning.h"
-
-struct NoDefault {
- NoDefault(int) {}
-};
-
-
-int main(int, char**)
-{
- {
- typedef double T;
- typedef std::array<T, 3> C;
- C c = {1, 2, 3.5};
- C::iterator i;
- i = c.begin();
- assert(*i == 1);
- assert(&*i == c.data());
- *i = 5.5;
- assert(c[0] == 5.5);
- }
- {
- typedef NoDefault T;
- typedef std::array<T, 0> C;
- C c = {};
- C::iterator ib, ie;
- ib = c.begin();
- ie = c.end();
- assert(ib == ie);
- LIBCPP_ASSERT(ib != nullptr);
- LIBCPP_ASSERT(ie != nullptr);
- }
-
- return 0;
-}
diff --git a/libcxx/test/std/containers/sequences/array/compare.pass.cpp b/libcxx/test/std/containers/sequences/array/compare.pass.cpp
index c05dd19..c89216c 100644
--- a/libcxx/test/std/containers/sequences/array/compare.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/compare.pass.cpp
@@ -8,17 +8,15 @@
// <array>
-// These are all constexpr in C++20
-// bool operator==(array<T, N> const&, array<T, N> const&);
-// bool operator!=(array<T, N> const&, array<T, N> const&);
-// bool operator<(array<T, N> const&, array<T, N> const&);
-// bool operator<=(array<T, N> const&, array<T, N> const&);
-// bool operator>(array<T, N> const&, array<T, N> const&);
-// bool operator>=(array<T, N> const&, array<T, N> const&);
+// bool operator==(array<T, N> const&, array<T, N> const&); // constexpr in C++20
+// bool operator!=(array<T, N> const&, array<T, N> const&); // constexpr in C++20
+// bool operator<(array<T, N> const&, array<T, N> const&); // constexpr in C++20
+// bool operator<=(array<T, N> const&, array<T, N> const&); // constexpr in C++20
+// bool operator>(array<T, N> const&, array<T, N> const&); // constexpr in C++20
+// bool operator>=(array<T, N> const&, array<T, N> const&); // constexpr in C++20
#include <array>
-#include <vector>
#include <cassert>
#include "test_macros.h"
@@ -28,36 +26,33 @@
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
+TEST_CONSTEXPR_CXX20 bool tests()
+{
+ {
+ typedef std::array<int, 3> C;
+ C c1 = {1, 2, 3};
+ C c2 = {1, 2, 3};
+ C c3 = {3, 2, 1};
+ C c4 = {1, 2, 1};
+ assert(testComparisons6(c1, c2, true, false));
+ assert(testComparisons6(c1, c3, false, true));
+ assert(testComparisons6(c1, c4, false, false));
+ }
+ {
+ typedef std::array<int, 0> C;
+ C c1 = {};
+ C c2 = {};
+ assert(testComparisons6(c1, c2, true, false));
+ }
+
+ return true;
+}
+
int main(int, char**)
{
- {
- typedef int T;
- typedef std::array<T, 3> C;
- C c1 = {1, 2, 3};
- C c2 = {1, 2, 3};
- C c3 = {3, 2, 1};
- C c4 = {1, 2, 1};
- assert(testComparisons6(c1, c2, true, false));
- assert(testComparisons6(c1, c3, false, true));
- assert(testComparisons6(c1, c4, false, false));
- }
- {
- typedef int T;
- typedef std::array<T, 0> C;
- C c1 = {};
- C c2 = {};
- assert(testComparisons6(c1, c2, true, false));
- }
-
-#if TEST_STD_VER > 17
- {
- constexpr std::array<int, 3> a1 = {1, 2, 3};
- constexpr std::array<int, 3> a2 = {2, 3, 4};
- static_assert(testComparisons6(a1, a1, true, false), "");
- static_assert(testComparisons6(a1, a2, false, true), "");
- static_assert(testComparisons6(a2, a1, false, false), "");
- }
+ tests();
+#if TEST_STD_VER >= 20
+ static_assert(tests(), "");
#endif
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/contiguous.pass.cpp b/libcxx/test/std/containers/sequences/array/contiguous.pass.cpp
index 41a7153..9589e63 100644
--- a/libcxx/test/std/containers/sequences/array/contiguous.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/contiguous.pass.cpp
@@ -15,20 +15,33 @@
#include "test_macros.h"
-template <class C>
-void test_contiguous ( const C &c )
+template <class Container>
+TEST_CONSTEXPR_CXX14 void assert_contiguous(Container const& c)
{
- for ( size_t i = 0; i < c.size(); ++i )
- assert ( *(c.begin() + i) == *(std::addressof(*c.begin()) + i));
+ for (size_t i = 0; i < c.size(); ++i)
+ assert(*(c.begin() + i) == *(std::addressof(*c.begin()) + i));
+}
+
+TEST_CONSTEXPR_CXX17 bool tests()
+{
+ assert_contiguous(std::array<double, 0>());
+ assert_contiguous(std::array<double, 1>());
+ assert_contiguous(std::array<double, 2>());
+ assert_contiguous(std::array<double, 3>());
+
+ assert_contiguous(std::array<char, 0>());
+ assert_contiguous(std::array<char, 1>());
+ assert_contiguous(std::array<char, 2>());
+ assert_contiguous(std::array<char, 3>());
+
+ return true;
}
int main(int, char**)
{
- {
- typedef double T;
- typedef std::array<T, 3> C;
- test_contiguous (C());
- }
-
- return 0;
+ tests();
+#if TEST_STD_VER >= 17 // begin() & friends are constexpr in >= C++17 only
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/empty.pass.cpp b/libcxx/test/std/containers/sequences/array/empty.pass.cpp
index a17aa50..8b61575 100644
--- a/libcxx/test/std/containers/sequences/array/empty.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/empty.pass.cpp
@@ -10,28 +10,45 @@
// class array
-// bool empty() const noexcept;
+// constexpr bool empty() const noexcept;
#include <array>
#include <cassert>
#include "test_macros.h"
-#include "min_allocator.h"
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef std::array<int, 2> C;
+ C c = {};
+ ASSERT_NOEXCEPT(c.empty());
+ assert(!c.empty());
+ }
+ {
+ typedef std::array<int, 0> C;
+ C c = {};
+ ASSERT_NOEXCEPT(c.empty());
+ assert(c.empty());
+ }
+
+ return true;
+}
int main(int, char**)
{
- {
- typedef std::array<int, 2> C;
- C c;
- ASSERT_NOEXCEPT(c.empty());
- assert(!c.empty());
- }
- {
- typedef std::array<int, 0> C;
- C c;
- ASSERT_NOEXCEPT(c.empty());
- assert( c.empty());
- }
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
- return 0;
+#if TEST_STD_VER >= 11
+ // Sanity check for constexpr in C++11
+ {
+ constexpr std::array<int, 3> array = {};
+ static_assert(!array.empty(), "");
+ }
+#endif
+
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/front_back.pass.cpp b/libcxx/test/std/containers/sequences/array/front_back.pass.cpp
index 5e0cb08..18985e9 100644
--- a/libcxx/test/std/containers/sequences/array/front_back.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/front_back.pass.cpp
@@ -8,10 +8,8 @@
// <array>
-// reference front(); // constexpr in C++17
-// reference back(); // constexpr in C++17
-// const_reference front(); // constexpr in C++14
-// const_reference back(); // constexpr in C++14
+// reference front(); // constexpr in C++17
+// reference back(); // constexpr in C++17
#include <array>
#include <cassert>
@@ -22,21 +20,8 @@
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
-#if TEST_STD_VER > 14
-constexpr bool check_front( double val )
-{
- std::array<double, 3> arr = {1, 2, 3.5};
- return arr.front() == val;
-}
-constexpr bool check_back( double val )
-{
- std::array<double, 3> arr = {1, 2, 3.5};
- return arr.back() == val;
-}
-#endif
-
-int main(int, char**)
+TEST_CONSTEXPR_CXX17 bool tests()
{
{
typedef double T;
@@ -55,74 +40,39 @@
}
{
typedef double T;
- typedef std::array<T, 3> C;
- const C c = {1, 2, 3.5};
- C::const_reference r1 = c.front();
- assert(r1 == 1);
-
- C::const_reference r2 = c.back();
- assert(r2 == 3.5);
+ typedef std::array<T, 0> C;
+ C c = {};
+ ASSERT_SAME_TYPE(decltype(c.back()), C::reference);
+ LIBCPP_ASSERT_NOEXCEPT(c.back());
+ ASSERT_SAME_TYPE(decltype(c.front()), C::reference);
+ LIBCPP_ASSERT_NOEXCEPT(c.front());
+ if (c.size() > (0)) { // always false
+ TEST_IGNORE_NODISCARD c.front();
+ TEST_IGNORE_NODISCARD c.back();
+ }
}
{
- typedef double T;
- typedef std::array<T, 0> C;
- C c = {};
- C const& cc = c;
- ASSERT_SAME_TYPE(decltype( c.back()), typename C::reference);
- ASSERT_SAME_TYPE(decltype(cc.back()), typename C::const_reference);
- LIBCPP_ASSERT_NOEXCEPT( c.back());
- LIBCPP_ASSERT_NOEXCEPT( cc.back());
- ASSERT_SAME_TYPE(decltype( c.front()), typename C::reference);
- ASSERT_SAME_TYPE(decltype(cc.front()), typename C::const_reference);
- LIBCPP_ASSERT_NOEXCEPT( c.front());
- LIBCPP_ASSERT_NOEXCEPT( cc.front());
- if (c.size() > (0)) { // always false
- TEST_IGNORE_NODISCARD c.front();
- TEST_IGNORE_NODISCARD c.back();
- TEST_IGNORE_NODISCARD cc.front();
- TEST_IGNORE_NODISCARD cc.back();
- }
- }
- {
- typedef double T;
- typedef std::array<const T, 0> C;
- C c = {{}};
- C const& cc = c;
- ASSERT_SAME_TYPE(decltype( c.back()), typename C::reference);
- ASSERT_SAME_TYPE(decltype(cc.back()), typename C::const_reference);
- LIBCPP_ASSERT_NOEXCEPT( c.back());
- LIBCPP_ASSERT_NOEXCEPT( cc.back());
- ASSERT_SAME_TYPE(decltype( c.front()), typename C::reference);
- ASSERT_SAME_TYPE(decltype(cc.front()), typename C::const_reference);
- LIBCPP_ASSERT_NOEXCEPT( c.front());
- LIBCPP_ASSERT_NOEXCEPT( cc.front());
- if (c.size() > (0)) {
- TEST_IGNORE_NODISCARD c.front();
- TEST_IGNORE_NODISCARD c.back();
- TEST_IGNORE_NODISCARD cc.front();
- TEST_IGNORE_NODISCARD cc.back();
- }
- }
-#if TEST_STD_VER > 11
- {
typedef double T;
- typedef std::array<T, 3> C;
- constexpr C c = {1, 2, 3.5};
-
- constexpr T t1 = c.front();
- static_assert (t1 == 1, "");
-
- constexpr T t2 = c.back();
- static_assert (t2 == 3.5, "");
+ typedef std::array<const T, 0> C;
+ C c = {};
+ ASSERT_SAME_TYPE(decltype( c.back()), C::reference);
+ LIBCPP_ASSERT_NOEXCEPT( c.back());
+ ASSERT_SAME_TYPE(decltype( c.front()), C::reference);
+ LIBCPP_ASSERT_NOEXCEPT( c.front());
+ if (c.size() > (0)) {
+ TEST_IGNORE_NODISCARD c.front();
+ TEST_IGNORE_NODISCARD c.back();
+ }
}
-#endif
-#if TEST_STD_VER > 14
- {
- static_assert (check_front(1), "");
- static_assert (check_back (3.5), "");
- }
-#endif
+ return true;
+}
- return 0;
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 17
+ static_assert(tests(), "");
+#endif
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/front_back_const.pass.cpp b/libcxx/test/std/containers/sequences/array/front_back_const.pass.cpp
new file mode 100644
index 0000000..af51912
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/array/front_back_const.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <array>
+
+// const_reference front() const; // constexpr in C++14
+// const_reference back() const; // constexpr in C++14
+
+#include <array>
+#include <cassert>
+
+#include "test_macros.h"
+
+// std::array is explicitly allowed to be initialized with A a = { init-list };.
+// Disable the missing braces warning for this reason.
+#include "disable_missing_braces_warning.h"
+
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef double T;
+ typedef std::array<T, 3> C;
+ C const c = {1, 2, 3.5};
+ C::const_reference r1 = c.front();
+ assert(r1 == 1);
+
+ C::const_reference r2 = c.back();
+ assert(r2 == 3.5);
+ }
+ {
+ typedef double T;
+ typedef std::array<T, 0> C;
+ C const c = {};
+ ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference);
+ LIBCPP_ASSERT_NOEXCEPT(c.back());
+ ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference);
+ LIBCPP_ASSERT_NOEXCEPT(c.front());
+ if (c.size() > (0)) { // always false
+ TEST_IGNORE_NODISCARD c.front();
+ TEST_IGNORE_NODISCARD c.back();
+ }
+ }
+ {
+ typedef double T;
+ typedef std::array<const T, 0> C;
+ C const c = {};
+ ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference);
+ LIBCPP_ASSERT_NOEXCEPT(c.back());
+ ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference);
+ LIBCPP_ASSERT_NOEXCEPT(c.front());
+ if (c.size() > (0)) {
+ TEST_IGNORE_NODISCARD c.front();
+ TEST_IGNORE_NODISCARD c.back();
+ }
+ }
+
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/array/indexing.pass.cpp b/libcxx/test/std/containers/sequences/array/indexing.pass.cpp
index 0df672d..6b5d848 100644
--- a/libcxx/test/std/containers/sequences/array/indexing.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/indexing.pass.cpp
@@ -8,11 +8,8 @@
// <array>
-// reference operator[] (size_type)
-// const_reference operator[] (size_type); // constexpr in C++14
-// reference at (size_type)
-// const_reference at (size_type); // constexpr in C++14
-// Libc++ marks these as noexcept
+// reference operator[](size_type); // constexpr in C++17
+// Libc++ marks it as noexcept
#include <array>
#include <cassert>
@@ -23,15 +20,8 @@
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
-#if TEST_STD_VER > 14
-constexpr bool check_idx( size_t idx, double val )
-{
- std::array<double, 3> arr = {1, 2, 3.5};
- return arr[idx] == val;
-}
-#endif
-int main(int, char**)
+TEST_CONSTEXPR_CXX17 bool tests()
{
{
typedef double T;
@@ -49,72 +39,41 @@
r2 = 7.5;
assert(c.back() == 7.5);
}
+
+ // Test operator[] "works" on zero sized arrays
{
- typedef double T;
- typedef std::array<T, 3> C;
- const C c = {1, 2, 3.5};
- LIBCPP_ASSERT_NOEXCEPT(c[0]);
- ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
- C::const_reference r1 = c[0];
- assert(r1 == 1);
- C::const_reference r2 = c[2];
- assert(r2 == 3.5);
- }
- { // Test operator[] "works" on zero sized arrays
- typedef double T;
- typedef std::array<T, 0> C;
- C c = {};
- C const& cc = c;
- LIBCPP_ASSERT_NOEXCEPT(c[0]);
- LIBCPP_ASSERT_NOEXCEPT(cc[0]);
- ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
- ASSERT_SAME_TYPE(C::const_reference, decltype(cc[0]));
- if (c.size() > (0)) { // always false
- C::reference r1 = c[0];
- C::const_reference r2 = cc[0];
- ((void)r1);
- ((void)r2);
+ {
+ typedef double T;
+ typedef std::array<T, 0> C;
+ C c = {};
+ LIBCPP_ASSERT_NOEXCEPT(c[0]);
+ ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
+ if (c.size() > (0)) { // always false
+ C::reference r = c[0];
+ (void)r;
+ }
+ }
+ {
+ typedef double T;
+ typedef std::array<const T, 0> C;
+ C c = {};
+ LIBCPP_ASSERT_NOEXCEPT(c[0]);
+ ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
+ if (c.size() > (0)) { // always false
+ C::reference r = c[0];
+ (void)r;
+ }
}
}
- { // Test operator[] "works" on zero sized arrays
- typedef double T;
- typedef std::array<const T, 0> C;
- C c = {{}};
- C const& cc = c;
- LIBCPP_ASSERT_NOEXCEPT(c[0]);
- LIBCPP_ASSERT_NOEXCEPT(cc[0]);
- ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
- ASSERT_SAME_TYPE(C::const_reference, decltype(cc[0]));
- if (c.size() > (0)) { // always false
- C::reference r1 = c[0];
- C::const_reference r2 = cc[0];
- ((void)r1);
- ((void)r2);
- }
- }
-#if TEST_STD_VER > 11
- {
- typedef double T;
- typedef std::array<T, 3> C;
- constexpr C c = {1, 2, 3.5};
- LIBCPP_ASSERT_NOEXCEPT(c[0]);
- ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
- constexpr T t1 = c[0];
- static_assert (t1 == 1, "");
+ return true;
+}
- constexpr T t2 = c[2];
- static_assert (t2 == 3.5, "");
- }
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 17
+ static_assert(tests(), "");
#endif
-
-#if TEST_STD_VER > 14
- {
- static_assert (check_idx(0, 1), "");
- static_assert (check_idx(1, 2), "");
- static_assert (check_idx(2, 3.5), "");
- }
-#endif
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/indexing_const.pass.cpp b/libcxx/test/std/containers/sequences/array/indexing_const.pass.cpp
new file mode 100644
index 0000000..3f34dfe
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/array/indexing_const.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <array>
+
+// const_reference operator[](size_type) const; // constexpr in C++14
+// Libc++ marks it as noexcept
+
+#include <array>
+#include <cassert>
+
+#include "test_macros.h"
+
+// std::array is explicitly allowed to be initialized with A a = { init-list };.
+// Disable the missing braces warning for this reason.
+#include "disable_missing_braces_warning.h"
+
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef double T;
+ typedef std::array<T, 3> C;
+ C const c = {1, 2, 3.5};
+ LIBCPP_ASSERT_NOEXCEPT(c[0]);
+ ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
+ C::const_reference r1 = c[0];
+ assert(r1 == 1);
+ C::const_reference r2 = c[2];
+ assert(r2 == 3.5);
+ }
+ // Test operator[] "works" on zero sized arrays
+ {
+ {
+ typedef double T;
+ typedef std::array<T, 0> C;
+ C const c = {};
+ LIBCPP_ASSERT_NOEXCEPT(c[0]);
+ ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
+ if (c.size() > (0)) { // always false
+ C::const_reference r = c[0];
+ (void)r;
+ }
+ }
+ {
+ typedef double T;
+ typedef std::array<T const, 0> C;
+ C const c = {};
+ LIBCPP_ASSERT_NOEXCEPT(c[0]);
+ ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
+ if (c.size() > (0)) { // always false
+ C::const_reference r = c[0];
+ (void)r;
+ }
+ }
+ }
+
+ return true;
+}
+
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp
index 71fad18..39d8a1a 100644
--- a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp
@@ -8,7 +8,20 @@
// <array>
-// iterator, const_iterator
+// iterator begin() noexcept; // constexpr in C++17
+// const_iterator begin() const noexcept; // constexpr in C++17
+// iterator end() noexcept; // constexpr in C++17
+// const_iterator end() const noexcept; // constexpr in C++17
+//
+// reverse_iterator rbegin() noexcept; // constexpr in C++17
+// const_reverse_iterator rbegin() const noexcept; // constexpr in C++17
+// reverse_iterator rend() noexcept; // constexpr in C++17
+// const_reverse_iterator rend() const noexcept; // constexpr in C++17
+//
+// const_iterator cbegin() const noexcept; // constexpr in C++17
+// const_iterator cend() const noexcept; // constexpr in C++17
+// const_reverse_iterator crbegin() const noexcept; // constexpr in C++17
+// const_reverse_iterator crend() const noexcept; // constexpr in C++17
#include <array>
#include <iterator>
@@ -20,127 +33,157 @@
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
-int main(int, char**)
+struct NoDefault {
+ TEST_CONSTEXPR NoDefault(int) { }
+};
+
+TEST_CONSTEXPR_CXX17 bool tests()
{
{
- typedef std::array<int, 5> C;
- C c;
- C::iterator i;
- i = c.begin();
- C::const_iterator j;
- j = c.cbegin();
- assert(i == j);
+ typedef std::array<int, 5> C;
+ C array = {};
+ typename C::iterator i = array.begin();
+ typename C::const_iterator j = array.cbegin();
+ assert(i == j);
}
{
- typedef std::array<int, 0> C;
- C c;
- C::iterator i;
- i = c.begin();
- C::const_iterator j;
- j = c.cbegin();
- assert(i == j);
+ typedef std::array<int, 0> C;
+ C array = {};
+ typename C::iterator i = array.begin();
+ typename C::const_iterator j = array.cbegin();
+ assert(i == j);
+ LIBCPP_ASSERT(i != nullptr);
+ LIBCPP_ASSERT(j != nullptr);
}
-#if TEST_STD_VER > 11
+ {
+ typedef std::array<int, 0> C;
+ C array = {};
+ typename C::iterator i = array.begin();
+ typename C::const_iterator j = array.cbegin();
+ assert(i == array.end());
+ assert(j == array.cend());
+ LIBCPP_ASSERT(i != nullptr);
+ LIBCPP_ASSERT(j != nullptr);
+ }
+ {
+ typedef std::array<int, 1> C;
+ C array = {1};
+ typename C::iterator i = array.begin();
+ assert(*i == 1);
+ assert(&*i == array.data());
+ *i = 99;
+ assert(array[0] == 99);
+ }
+ {
+ typedef std::array<int, 2> C;
+ C array = {1, 2};
+ typename C::iterator i = array.begin();
+ assert(*i == 1);
+ assert(&*i == array.data());
+ *i = 99;
+ assert(array[0] == 99);
+ assert(array[1] == 2);
+ }
+ {
+ typedef std::array<double, 3> C;
+ C array = {1, 2, 3.5};
+ typename C::iterator i = array.begin();
+ assert(*i == 1);
+ assert(&*i == array.data());
+ *i = 5.5;
+ assert(array[0] == 5.5);
+ assert(array[1] == 2.0);
+ }
+ {
+ typedef std::array<NoDefault, 0> C;
+ C array = {};
+ typename C::iterator ib = array.begin();
+ typename C::iterator ie = array.end();
+ assert(ib == ie);
+ LIBCPP_ASSERT(ib != nullptr);
+ LIBCPP_ASSERT(ie != nullptr);
+ }
+
+#if TEST_STD_VER >= 14
{ // N3644 testing
{
- typedef std::array<int, 5> C;
- C::iterator ii1{}, ii2{};
- C::iterator ii4 = ii1;
- C::const_iterator cii{};
- assert ( ii1 == ii2 );
- assert ( ii1 == ii4 );
- assert ( ii1 == cii );
+ typedef std::array<int, 5> C;
+ C::iterator ii1{}, ii2{};
+ C::iterator ii4 = ii1;
+ C::const_iterator cii{};
+ assert(ii1 == ii2);
+ assert(ii1 == ii4);
+ assert(ii1 == cii);
- assert ( !(ii1 != ii2 ));
- assert ( !(ii1 != cii ));
+ assert(!(ii1 != ii2));
+ assert(!(ii1 != cii));
- C c;
- assert ( c.begin() == std::begin(c));
- assert ( c.cbegin() == std::cbegin(c));
- assert ( c.rbegin() == std::rbegin(c));
- assert ( c.crbegin() == std::crbegin(c));
- assert ( c.end() == std::end(c));
- assert ( c.cend() == std::cend(c));
- assert ( c.rend() == std::rend(c));
- assert ( c.crend() == std::crend(c));
+ C c = {};
+ assert(c.begin() == std::begin(c));
+ assert(c.cbegin() == std::cbegin(c));
+ assert(c.rbegin() == std::rbegin(c));
+ assert(c.crbegin() == std::crbegin(c));
+ assert(c.end() == std::end(c));
+ assert(c.cend() == std::cend(c));
+ assert(c.rend() == std::rend(c));
+ assert(c.crend() == std::crend(c));
- assert ( std::begin(c) != std::end(c));
- assert ( std::rbegin(c) != std::rend(c));
- assert ( std::cbegin(c) != std::cend(c));
- assert ( std::crbegin(c) != std::crend(c));
+ assert(std::begin(c) != std::end(c));
+ assert(std::rbegin(c) != std::rend(c));
+ assert(std::cbegin(c) != std::cend(c));
+ assert(std::crbegin(c) != std::crend(c));
}
{
- typedef std::array<int, 0> C;
- C::iterator ii1{}, ii2{};
- C::iterator ii4 = ii1;
- C::const_iterator cii{};
- assert ( ii1 == ii2 );
- assert ( ii1 == ii4 );
+ typedef std::array<int, 0> C;
+ C::iterator ii1{}, ii2{};
+ C::iterator ii4 = ii1;
+ C::const_iterator cii{};
+ assert(ii1 == ii2);
+ assert(ii1 == ii4);
- assert (!(ii1 != ii2 ));
+ assert(!(ii1 != ii2));
- assert ( (ii1 == cii ));
- assert ( (cii == ii1 ));
- assert (!(ii1 != cii ));
- assert (!(cii != ii1 ));
- assert (!(ii1 < cii ));
- assert (!(cii < ii1 ));
- assert ( (ii1 <= cii ));
- assert ( (cii <= ii1 ));
- assert (!(ii1 > cii ));
- assert (!(cii > ii1 ));
- assert ( (ii1 >= cii ));
- assert ( (cii >= ii1 ));
- assert (cii - ii1 == 0);
- assert (ii1 - cii == 0);
+ assert( (ii1 == cii));
+ assert( (cii == ii1));
+ assert(!(ii1 != cii));
+ assert(!(cii != ii1));
+ assert(!(ii1 < cii));
+ assert(!(cii < ii1));
+ assert( (ii1 <= cii));
+ assert( (cii <= ii1));
+ assert(!(ii1 > cii));
+ assert(!(cii > ii1));
+ assert( (ii1 >= cii));
+ assert( (cii >= ii1));
+ assert(cii - ii1 == 0);
+ assert(ii1 - cii == 0);
- C c;
- assert ( c.begin() == std::begin(c));
- assert ( c.cbegin() == std::cbegin(c));
- assert ( c.rbegin() == std::rbegin(c));
- assert ( c.crbegin() == std::crbegin(c));
- assert ( c.end() == std::end(c));
- assert ( c.cend() == std::cend(c));
- assert ( c.rend() == std::rend(c));
- assert ( c.crend() == std::crend(c));
+ C c = {};
+ assert(c.begin() == std::begin(c));
+ assert(c.cbegin() == std::cbegin(c));
+ assert(c.rbegin() == std::rbegin(c));
+ assert(c.crbegin() == std::crbegin(c));
+ assert(c.end() == std::end(c));
+ assert(c.cend() == std::cend(c));
+ assert(c.rend() == std::rend(c));
+ assert(c.crend() == std::crend(c));
- assert ( std::begin(c) == std::end(c));
- assert ( std::rbegin(c) == std::rend(c));
- assert ( std::cbegin(c) == std::cend(c));
- assert ( std::crbegin(c) == std::crend(c));
+ assert(std::begin(c) == std::end(c));
+ assert(std::rbegin(c) == std::rend(c));
+ assert(std::cbegin(c) == std::cend(c));
+ assert(std::crbegin(c) == std::crend(c));
}
}
#endif
-#if TEST_STD_VER > 14
- {
- typedef std::array<int, 5> C;
- constexpr C c{0,1,2,3,4};
+ return true;
+}
- static_assert ( c.begin() == std::begin(c), "");
- static_assert ( c.cbegin() == std::cbegin(c), "");
- static_assert ( c.end() == std::end(c), "");
- static_assert ( c.cend() == std::cend(c), "");
-
- static_assert ( c.rbegin() == std::rbegin(c), "");
- static_assert ( c.crbegin() == std::crbegin(c), "");
- static_assert ( c.rend() == std::rend(c), "");
- static_assert ( c.crend() == std::crend(c), "");
-
- static_assert ( std::begin(c) != std::end(c), "");
- static_assert ( std::rbegin(c) != std::rend(c), "");
- static_assert ( std::cbegin(c) != std::cend(c), "");
- static_assert ( std::crbegin(c) != std::crend(c), "");
-
- static_assert ( *c.begin() == 0, "");
- static_assert ( *c.rbegin() == 4, "");
-
- static_assert ( *std::begin(c) == 0, "" );
- static_assert ( *std::cbegin(c) == 0, "" );
- static_assert ( *std::rbegin(c) == 4, "" );
- static_assert ( *std::crbegin(c) == 4, "" );
- }
+int main(int, char**)
+{
+ tests();
+#if TEST_STD_VER >= 17
+ static_assert(tests(), "");
#endif
-
return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/max_size.pass.cpp b/libcxx/test/std/containers/sequences/array/max_size.pass.cpp
index a0b7739..8ca8cd4 100644
--- a/libcxx/test/std/containers/sequences/array/max_size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/max_size.pass.cpp
@@ -10,28 +10,45 @@
// class array
-// bool max_size() const noexcept;
+// constexpr bool max_size() const noexcept;
#include <array>
#include <cassert>
#include "test_macros.h"
-#include "min_allocator.h"
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef std::array<int, 2> C;
+ C c = {};
+ ASSERT_NOEXCEPT(c.max_size());
+ assert(c.max_size() == 2);
+ }
+ {
+ typedef std::array<int, 0> C;
+ C c = {};
+ ASSERT_NOEXCEPT(c.max_size());
+ assert(c.max_size() == 0);
+ }
+
+ return true;
+}
int main(int, char**)
{
- {
- typedef std::array<int, 2> C;
- C c;
- ASSERT_NOEXCEPT(c.max_size());
- assert(c.max_size() == 2);
- }
- {
- typedef std::array<int, 0> C;
- C c;
- ASSERT_NOEXCEPT(c.max_size());
- assert(c.max_size() == 0);
- }
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
- return 0;
+#if TEST_STD_VER >= 11
+ // Sanity check for constexpr in C++11
+ {
+ constexpr std::array<int, 3> array = {};
+ static_assert(array.max_size() == 3, "");
+ }
+#endif
+
+ return 0;
}
diff --git a/libcxx/test/std/containers/sequences/array/size_and_alignment.pass.cpp b/libcxx/test/std/containers/sequences/array/size_and_alignment.pass.cpp
index 51982ea..11eac5c 100644
--- a/libcxx/test/std/containers/sequences/array/size_and_alignment.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/size_and_alignment.pass.cpp
@@ -34,12 +34,6 @@
static_assert(sizeof(ArrayT) == sizeof(CArrayT), "");
static_assert(sizeof(ArrayT) == sizeof(MyArrayT), "");
static_assert(TEST_ALIGNOF(ArrayT) == TEST_ALIGNOF(MyArrayT), "");
-#if defined(_LIBCPP_VERSION)
- ArrayT a;
- ((void)a);
- static_assert(sizeof(ArrayT) == sizeof(a.__elems_), "");
- static_assert(TEST_ALIGNOF(ArrayT) == __alignof__(a.__elems_), "");
-#endif
}
template <class T>
@@ -67,8 +61,6 @@
};
#endif
-//static_assert(sizeof(void*) == 4, "");
-
int main(int, char**) {
test_type<char>();
test_type<int>();