-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][test] Only views::split(pattern)
can be piped
#74961
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
[libc++][test] Only views::split(pattern)
can be piped
#74961
Conversation
This was failing with: D:\GitHub\STL\llvm-project\libcxx\test\std\ranges\range.adaptors\range.split\adaptor.pass.cpp(42,1): error: static assertion failed static_assert( CanBePiped<SomeView&, decltype(std::views::split)>); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:\GitHub\STL\llvm-project\libcxx\test\std\ranges\range.adaptors\range.split\adaptor.pass.cpp(42,16): note: because 'CanBePiped<SomeView &, decltype(std::views::split)>' evaluated to false static_assert( CanBePiped<SomeView&, decltype(std::views::split)>); ^ D:\GitHub\STL\llvm-project\libcxx\test\std\ranges\range.adaptors\range.split\adaptor.pass.cpp(25,30): note: because 'std::forward<View>(view) | std::forward<T>(t)' would be invalid: invalid operands to binary expression ('SomeView' and 'const std::ranges::views::_Split_fn') { std::forward<View>(view) | std::forward<T>(t) }; ^ D:\GitHub\STL\llvm-project\libcxx\test\std\ranges\range.adaptors\range.split\adaptor.pass.cpp(43,1): error: static assertion failed static_assert( CanBePiped<char(&)[10], decltype(std::views::split)>); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:\GitHub\STL\llvm-project\libcxx\test\std\ranges\range.adaptors\range.split\adaptor.pass.cpp(43,16): note: because 'CanBePiped<char (&)[10], decltype(std::views::split)>' evaluated to false static_assert( CanBePiped<char(&)[10], decltype(std::views::split)>); ^ D:\GitHub\STL\llvm-project\libcxx\test\std\ranges\range.adaptors\range.split\adaptor.pass.cpp(25,30): note: because 'std::forward<View>(view) | std::forward<T>(t)' would be invalid: invalid operands to binary expression ('char[10]' and 'const std::ranges::views::_Split_fn') { std::forward<View>(view) | std::forward<T>(t) }; ^ Similarly for range.lazy.split/adaptor.pass.cpp.
@llvm/pr-subscribers-libcxx Author: Stephan T. Lavavej (StephanTLavavej) ChangesFound while running libc++'s tests with MSVC's STL.
To summarize: This PR adjusts the test coverage accordingly. Note: The fact that the tests were previously passing may indicate the existence of a bug (or an extension?) in libc++'s product code. I looked at the machinery briefly but it was far beyond me (I barely understand microsoft/STL's ranges machinery). As this PR changes the tests to be portable, I would like to request that if changes to libc++'s product code are desired, that should be done in a followup PR (and I can file a followup issue if a reminder is desired). <details><summary>Click to expand the Clang compiler error that discovered this:</summary>
</details> Full diff: https://github.com/llvm/llvm-project/pull/74961.diff 2 Files Affected:
diff --git a/libcxx/test/std/ranges/range.adaptors/range.lazy.split/adaptor.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.lazy.split/adaptor.pass.cpp
index da4bd9fbbe1794..58be3713263c73 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.lazy.split/adaptor.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.lazy.split/adaptor.pass.cpp
@@ -40,10 +40,10 @@ static_assert(!std::is_invocable_v<decltype(std::views::lazy_split), SomeView, N
static_assert(!std::is_invocable_v<decltype(std::views::lazy_split), NotAView, SomeView>);
static_assert( std::is_invocable_v<decltype(std::views::lazy_split), SomeView, SomeView>);
-static_assert( CanBePiped<SomeView&, decltype(std::views::lazy_split)>);
-static_assert( CanBePiped<char(&)[10], decltype(std::views::lazy_split)>);
-static_assert(!CanBePiped<char(&&)[10], decltype(std::views::lazy_split)>);
-static_assert(!CanBePiped<NotAView, decltype(std::views::lazy_split)>);
+static_assert( CanBePiped<SomeView&, decltype(std::views::lazy_split('x'))>);
+static_assert( CanBePiped<char(&)[10], decltype(std::views::lazy_split('x'))>);
+static_assert(!CanBePiped<char(&&)[10], decltype(std::views::lazy_split('x'))>);
+static_assert(!CanBePiped<NotAView, decltype(std::views::lazy_split('x'))>);
static_assert(std::same_as<decltype(std::views::lazy_split), decltype(std::ranges::views::lazy_split)>);
diff --git a/libcxx/test/std/ranges/range.adaptors/range.split/adaptor.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.split/adaptor.pass.cpp
index cd12011daeab5d..4b13d1b361198f 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.split/adaptor.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.split/adaptor.pass.cpp
@@ -39,10 +39,10 @@ static_assert(!std::is_invocable_v<decltype(std::views::split), SomeView, NotAVi
static_assert(!std::is_invocable_v<decltype(std::views::split), NotAView, SomeView>);
static_assert( std::is_invocable_v<decltype(std::views::split), SomeView, SomeView>);
-static_assert( CanBePiped<SomeView&, decltype(std::views::split)>);
-static_assert( CanBePiped<char(&)[10], decltype(std::views::split)>);
-static_assert(!CanBePiped<char(&&)[10], decltype(std::views::split)>);
-static_assert(!CanBePiped<NotAView, decltype(std::views::split)>);
+static_assert( CanBePiped<SomeView&, decltype(std::views::split('x'))>);
+static_assert( CanBePiped<char(&)[10], decltype(std::views::split('x'))>);
+static_assert(!CanBePiped<char(&&)[10], decltype(std::views::split('x'))>);
+static_assert(!CanBePiped<NotAView, decltype(std::views::split('x'))>);
static_assert(std::same_as<decltype(std::views::split), decltype(std::ranges::views::split)>);
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
It seems that libc++'s llvm-project/libcxx/include/__ranges/split_view.h Lines 195 to 197 in b85f1f9
llvm-project/libcxx/include/__ranges/range_adaptor.h Lines 57 to 63 in b85f1f9
I think llvm-project/libcxx/include/__ranges/take_while_view.h Lines 134 to 137 in b85f1f9
|
Closing this PR as it has been superseded by #75266 which has passed stage1 checks (I'll wait for stage2 and stage3 before merging it, of course). |
…aptor closures (#75266) Fixes #75002. Found while running libc++'s tests with MSVC's STL. This is a superset of #74961 that also fixes the product code and adds a regression test. Thanks again, @cpplearner! To summarize: `views::split` and `views::lazy_split` aren't unary, aren't range adaptor **closure** objects, and can't be piped. However, \[range.adaptor.object\]/8 says that `views::split(pattern)` and `views::lazy_split(pattern)` produce unary, pipeable, range adaptor closure objects. This PR adjusts the test coverage accordingly, allowing it to portably pass for libc++ and MSVC's STL.
Found while running libc++'s tests with MSVC's STL.
To summarize:
views::split
andviews::lazy_split
aren't unary, aren't range adaptor closure objects, and can't be piped. However, [range.adaptor.object]/8 says thatviews::split(pattern)
andviews::lazy_split(pattern)
produce unary, pipeable, range adaptor closure objects.This PR adjusts the test coverage accordingly, allowing it to portably pass for libc++ and MSVC's STL.
Note: The fact that the tests were previously passing indicates the existence of a bug. @cpplearner figured out what was going on, so I filed #75002 to track followup changes for libc++'s product code.
Click to expand the Clang compiler error that discovered this: