[libcxx-commits] [libcxx] [libc++] tests with picolibc: Fix iterator diff_type to std::streamoff (PR #74072)

Dominik Wójt via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 1 06:53:40 PST 2023


https://github.com/domin144 updated https://github.com/llvm/llvm-project/pull/74072

>From b2f88d0b5116bba1d6d4a6cce1260b027b927f4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= <dominik.wojt at arm.com>
Date: Fri, 27 Oct 2023 14:33:48 +0200
Subject: [PATCH 1/3] [libc++] tests with picolibc: Fix iterator diff_type to
 std::streamoff

The hardcoded value of long int was not valid for newlib and picolibc.
---
 .../cxx20_iterator_traits.compile.pass.cpp                | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

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 f56750bb495e15f..3f8c9c2ad8d0221 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
@@ -11,11 +11,6 @@
 // This test uses iterator types from std::filesystem
 // XFAIL: availability-filesystem-missing
 
-// std::same_as<typename Traits::difference_type, DiffType> failed.
-// The former was long and the latter was long long.
-// Possibly related to "using streamoff = long int" in ios.h.
-// XFAIL: LIBCXX-PICOLIBC-FIXME
-
 // template<class T>
 // struct iterator_traits;
 
@@ -152,8 +147,7 @@ static_assert(testIOIterator<std::insert_iterator<std::vector<int>>, std::output
 static_assert(testConst<std::istream_iterator<int, char>, std::input_iterator_tag, int>());
 
 #if !defined(TEST_HAS_NO_LOCALIZATION)
-// libc++-specific since pointer type is unspecified:
-LIBCPP_STATIC_ASSERT(test<std::istreambuf_iterator<char>, std::input_iterator_tag, char, long long, char, char*>());
+static_assert(test<std::istreambuf_iterator<char>, std::input_iterator_tag, char, std::streamoff, char, char*>());
 static_assert(test<std::move_iterator<int*>, std::random_access_iterator_tag, int, std::ptrdiff_t, int&&, int*>());
 static_assert(testIOIterator<std::ostream_iterator<int, char>, std::output_iterator_tag>());
 static_assert(testIOIterator<std::ostreambuf_iterator<int, char>, std::output_iterator_tag>());

>From df185028ba3c787bc4cf5d26a1e28dfc3e93b85b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= <dominik.wojt at arm.com>
Date: Fri, 1 Dec 2023 15:36:43 +0100
Subject: [PATCH 2/3] Re-add the LIBCPP_STATIC_ASSERT

---
 .../iterator.traits/cxx20_iterator_traits.compile.pass.cpp     | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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 3f8c9c2ad8d0221..5dea3a00bfc3f6f 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
@@ -147,7 +147,8 @@ static_assert(testIOIterator<std::insert_iterator<std::vector<int>>, std::output
 static_assert(testConst<std::istream_iterator<int, char>, std::input_iterator_tag, int>());
 
 #if !defined(TEST_HAS_NO_LOCALIZATION)
-static_assert(test<std::istreambuf_iterator<char>, std::input_iterator_tag, char, std::streamoff, char, char*>());
+// libc++-specific since pointer type is unspecified:
+LIBCPP_STATIC_ASSERT(test<std::istreambuf_iterator<char>, std::input_iterator_tag, char, std::streamoff, char, char*>());
 static_assert(test<std::move_iterator<int*>, std::random_access_iterator_tag, int, std::ptrdiff_t, int&&, int*>());
 static_assert(testIOIterator<std::ostream_iterator<int, char>, std::output_iterator_tag>());
 static_assert(testIOIterator<std::ostreambuf_iterator<int, char>, std::output_iterator_tag>());

>From a19d96fc93380149aea9b038e4b0890eb055f7ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20W=C3=B3jt?= <dominik.wojt at arm.com>
Date: Fri, 1 Dec 2023 15:44:44 +0100
Subject: [PATCH 3/3] Remove LIBCPP_STATIC_ASSERT again, use iterator::pointer

---
 .../iterator.traits/cxx20_iterator_traits.compile.pass.cpp    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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 5dea3a00bfc3f6f..f7df4d1b35420c3 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
@@ -147,8 +147,8 @@ static_assert(testIOIterator<std::insert_iterator<std::vector<int>>, std::output
 static_assert(testConst<std::istream_iterator<int, char>, std::input_iterator_tag, int>());
 
 #if !defined(TEST_HAS_NO_LOCALIZATION)
-// libc++-specific since pointer type is unspecified:
-LIBCPP_STATIC_ASSERT(test<std::istreambuf_iterator<char>, std::input_iterator_tag, char, std::streamoff, char, char*>());
+// We use std::istreambuf_iterator<char>::pointer because it's unspecified, it doesn't have to be char*
+static_assert(test<std::istreambuf_iterator<char>, std::input_iterator_tag, char, std::streamoff, char, std::istreambuf_iterator<char>::pointer>());
 static_assert(test<std::move_iterator<int*>, std::random_access_iterator_tag, int, std::ptrdiff_t, int&&, int*>());
 static_assert(testIOIterator<std::ostream_iterator<int, char>, std::output_iterator_tag>());
 static_assert(testIOIterator<std::ostreambuf_iterator<int, char>, std::output_iterator_tag>());



More information about the libcxx-commits mailing list