[libcxx-commits] [libcxx] 997e128 - [libcxx][test] the domain of == for forward iterators is iterator values from the same range
Casey Carter via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 24 13:00:19 PST 2022
Author: Casey Carter
Date: 2022-01-24T13:00:07-08:00
New Revision: 997e128e2a78f5a5434fc75997441ae1ee76f8a4
URL: https://github.com/llvm/llvm-project/commit/997e128e2a78f5a5434fc75997441ae1ee76f8a4
DIFF: https://github.com/llvm/llvm-project/commit/997e128e2a78f5a5434fc75997441ae1ee76f8a4.diff
LOG: [libcxx][test] the domain of == for forward iterators is iterator values from the same range
* Default-initialized `basic_string` iterators are not portably in the domain of `==`.
* Avoid comparing iterators from non-equal string_views which MSVCSTL considers not to be in the domain of equality.
* Don't test invalid range `[in, out + N)`.
Also silence some truncation warnings by testing with a non-narrowing conversion.
Differential Revision: https://reviews.llvm.org/D118049
Added:
Modified:
libcxx/test/std/ranges/range.adaptors/range.all/range.owning.view/begin_end.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.transform/iterator/plus_minus.pass.cpp
libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp
libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy_n.pass.cpp
libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move.pass.cpp
libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move_n.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/ranges/range.adaptors/range.all/range.owning.view/begin_end.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.all/range.owning.view/begin_end.pass.cpp
index 9319ac3b8986a..34898f0d3df94 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.all/range.owning.view/begin_end.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.all/range.owning.view/begin_end.pass.cpp
@@ -117,10 +117,10 @@ constexpr bool test()
// Test a non-view.
std::array<int, 2> a = {1, 2};
auto ov = std::ranges::owning_view(std::move(a));
- assert(ov.begin() != a.begin()); // because it points into the copy
- assert(std::as_const(ov).begin() != a.begin());
- assert(ov.end() != a.end());
- assert(std::as_const(ov).end() != a.end());
+ assert(std::to_address(ov.begin()) != std::to_address(a.begin())); // because it points into the copy
+ assert(std::to_address(std::as_const(ov).begin()) != std::to_address(a.begin()));
+ assert(std::to_address(ov.end()) != std::to_address(a.end()));
+ assert(std::to_address(std::as_const(ov).end()) != std::to_address(a.end()));
}
return true;
}
diff --git a/libcxx/test/std/ranges/range.adaptors/range.transform/iterator/plus_minus.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.transform/iterator/plus_minus.pass.cpp
index 9baff10cc034d..6138df97929a2 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.transform/iterator/plus_minus.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.transform/iterator/plus_minus.pass.cpp
@@ -21,12 +21,12 @@ constexpr bool test() {
std::ranges::transform_view<MoveOnlyView, PlusOneMutable> transformView1;
auto iter1 = std::move(transformView1).begin();
std::ranges::transform_view<MoveOnlyView, PlusOneMutable> transformView2;
- auto iter2 = std::move(transformView2).begin();
+ [[maybe_unused]] auto iter2 = std::move(transformView2).begin();
iter1 += 4;
assert((iter1 + 1).base() == globalBuff + 5);
assert((1 + iter1).base() == globalBuff + 5);
assert((iter1 - 1).base() == globalBuff + 3);
- assert(iter1 - iter2 == 4);
+ LIBCPP_ASSERT(iter1 - iter2 == 4);
assert((iter1 + 2) - 2 == iter1);
assert((iter1 - 2) + 2 == iter1);
diff --git a/libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp b/libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
index 187452b6020e0..0ab3a549dd5af 100644
--- a/libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
@@ -54,7 +54,6 @@ TEST_CONSTEXPR_CXX20 void test()
C a;
typename C::iterator i1 = a.begin();
typename C::iterator i2;
- assert ( i1 != i2 );
i2 = i1;
assert ( i1 == i2 );
}
diff --git a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp
index fe0405f2e534c..d392f993343a6 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp
@@ -39,10 +39,10 @@ constexpr void test(const CharT* fmt) {
std::basic_format_parse_context context(view);
context.advance_to(context.begin() + 1);
- assert(context.begin() == view.begin() + 1);
+ assert(std::to_address(context.begin()) == std::to_address(view.begin()) + 1);
context.advance_to(context.begin() + 1);
- assert(context.begin() == view.begin() + 2);
+ assert(std::to_address(context.begin()) == std::to_address(view.begin()) + 2);
context.advance_to(context.begin() + 1);
assert(context.begin() == context.end());
diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
index f6b40fd145635..4ce2d720aa66f 100644
--- a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
+++ b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy.pass.cpp
@@ -218,7 +218,7 @@ int main(int, char**) {
constexpr int N = 5;
int in[N] = {1, 2, 3, 4, 5};
int out[N] = {6, 7, 8, 9, 10};
- assert(!std::equal(in, in + N, in, out + N));
+ assert(!std::equal(in, in + N, out, out + N));
std::ranges::uninitialized_copy(in, in + 1, out, out + N);
assert(out[0] == 1);
@@ -314,8 +314,8 @@ int main(int, char**) {
// Conversions, (iter, sentinel) overload.
{
constexpr int N = 3;
- double in[N] = {1.0, 2.0, 3.0};
- Buffer<int, N> out;
+ int in[N] = {1, 2, 3};
+ Buffer<double, N> out;
std::ranges::uninitialized_copy(in, in + N, out.begin(), out.end());
assert(std::equal(in, in + N, out.begin(), out.end()));
@@ -324,8 +324,8 @@ int main(int, char**) {
// Conversions, (range) overload.
{
constexpr int N = 3;
- double in[N] = {1.0, 2.0, 3.0};
- Buffer<int, N> out;
+ int in[N] = {1, 2, 3};
+ Buffer<double, N> out;
std::ranges::uninitialized_copy(in, out);
assert(std::equal(in, in + N, out.begin(), out.end()));
diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy_n.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy_n.pass.cpp
index f32af6cf4b38b..aee2cfd1f91b5 100644
--- a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy_n.pass.cpp
+++ b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/ranges_uninitialized_copy_n.pass.cpp
@@ -122,8 +122,8 @@ int main(int, char**) {
// Conversions.
{
constexpr int N = 3;
- double in[N] = {1.0, 2.0, 3.0};
- Buffer<int, N> out;
+ int in[N] = {1, 2, 3};
+ Buffer<double, N> out;
std::ranges::uninitialized_copy_n(in, N, out.begin(), out.end());
assert(std::equal(in, in + N, out.begin(), out.end()));
diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move.pass.cpp
index 934ac6a4f23fe..c764440d84e77 100644
--- a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move.pass.cpp
+++ b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move.pass.cpp
@@ -250,7 +250,7 @@ int main(int, char**) {
constexpr int N = 5;
int in[N] = {1, 2, 3, 4, 5};
int out[N] = {6, 7, 8, 9, 10};
- assert(!std::equal(in, in + N, in, out + N));
+ assert(!std::equal(in, in + N, out, out + N));
std::ranges::uninitialized_move(in, in + 1, out, out + N);
assert(out[0] == 1);
@@ -350,8 +350,8 @@ int main(int, char**) {
// Conversions, (iter, sentinel) overload.
{
constexpr int N = 3;
- double in[N] = {1.0, 2.0, 3.0};
- Buffer<int, N> out;
+ int in[N] = {1, 2, 3};
+ Buffer<double, N> out;
std::ranges::uninitialized_move(in, in + N, out.begin(), out.end());
assert(std::equal(in, in + N, out.begin(), out.end()));
@@ -360,8 +360,8 @@ int main(int, char**) {
// Conversions, (range) overload.
{
constexpr int N = 3;
- double in[N] = {1.0, 2.0, 3.0};
- Buffer<int, N> out;
+ int in[N] = {1, 2, 3};
+ Buffer<double, N> out;
std::ranges::uninitialized_move(in, out);
assert(std::equal(in, in + N, out.begin(), out.end()));
diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move_n.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move_n.pass.cpp
index 9c6691de92297..01f3c6ca8e00d 100644
--- a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move_n.pass.cpp
+++ b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.move/ranges_uninitialized_move_n.pass.cpp
@@ -156,8 +156,8 @@ int main(int, char**) {
// Conversions.
{
constexpr int N = 3;
- double in[N] = {1.0, 2.0, 3.0};
- Buffer<int, N> out;
+ int in[N] = {1, 2, 3};
+ Buffer<double, N> out;
std::ranges::uninitialized_move_n(in, N, out.begin(), out.end());
assert(std::equal(in, in + N, out.begin(), out.end()));
More information about the libcxx-commits
mailing list