Skip to content

[libc++] tests with picolibc: Fix iterator diff_type to std::streamoff #74072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 3, 2023

Conversation

domin144
Copy link
Contributor

@domin144 domin144 commented Dec 1, 2023

The hardcoded value of long int was not valid for newlib and picolibc.

@domin144 domin144 requested a review from a team as a code owner December 1, 2023 12:35
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 1, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-libcxx

Author: Dominik Wójt (domin144)

Changes

The hardcoded value of long int was not valid for newlib and picolibc.


Full diff: https://github.com/llvm/llvm-project/pull/74072.diff

1 Files Affected:

  • (modified) libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp (+1-7)
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>());

@domin144
Copy link
Contributor Author

domin144 commented Dec 1, 2023

@ldionne @zoecarver

The proposed check is no longer libc++ specific. It follows this derivation:

std::iterator_traits<std::istreambuf_iterator<char>>::difference_type
    = std::istreambuf_iterator<char>::difference_type
    = typename Traits::off_type (Traits = std::char_traits<char>)
    = std::char_traits<char>::off_type
    = std::streamoff

Further is libc++ specific. std::streamoff is defined in libcxx/include/__fwd/ios.h

    #if defined(_NEWLIB_VERSION)
    // On newlib, off_t is 'long int'
    using streamoff = long int; // for char_traits in <string>
    #else
    using streamoff = long long; // for char_traits in <string>
    #endif

As an alternative, the ifdefs from ios.h could be reproduced in the test, making it libc++ specific again.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the clean up.

@ldionne
Copy link
Member

ldionne commented Dec 1, 2023

Please rebase onto main and push again, it'll trigger the CI again. I just fixed an issue on GCC.

Copy link

github-actions bot commented Dec 1, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@domin144 domin144 force-pushed the libcxx_streamoff branch 3 times, most recently from a19d96f to a38d413 Compare December 1, 2023 14:54
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants