Skip to content
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] alg.find.last tests assume that std::array iterators are pointers #100498

Closed
StephanTLavavej opened this issue Jul 25, 2024 · 1 comment · Fixed by #100603
Closed
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite

Comments

@StephanTLavavej
Copy link
Member

Recently introduced by @strega-nil's #99312. See #74430 for previous fixes.

The following tests assume that std::array iterators are pointers, which isn't guaranteed by the Standard, and fails for MSVC's STL:

Each test emits many errors. I've attached full_error_logs.txt, and here is the full context for the first error emitted by each test (GitHub has a 64K character limit for issues, hence the attachment):

Click to expand first error for ranges.find_last.pass.cpp:
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp(64,34): error: cannot cast from type 'iterator' (aka '_Array_iterator<char, 0>') to pointer type 'char *'
   64 |     return std::ranges::subrange(It(std::ranges::begin(a)), Sent(It(std::ranges::end(a))));
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp(93,41): note: in instantiation of function template specialization 'test_iterators()::(anonymous class)::operator()<std::array<char, 0>>' requested here
   93 |       auto ret = std::ranges::find_last(make_range(a), 1).begin();
      |                                         ^
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp(163,7): note: in instantiation of function template specialization 'test_iterators<char *, char *>' requested here
  163 |       test_iterators<Iter>();
      |       ^
D:\GitHub\STL\llvm-project\libcxx\test\support/type_algorithms.h(52,23): note: in instantiation of function template specialization 'test()::(anonymous class)::operator()()::(anonymous class)::operator()<char *>' requested here
   52 |   swallow((f.template operator()<Types>(), 0)...);
      |                       ^
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp(162,12): note: in instantiation of function template specialization 'types::for_each<char *, contiguous_iterator<char *>, random_access_iterator<char *>, bidirectional_iterator<char *>, forward_iterator<char *>, (lambda at D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp:162:57)>' requested here
  162 |     types::for_each(types::forward_iterator_list<T*>{}, []<class Iter> {
      |            ^
D:\GitHub\STL\llvm-project\libcxx\test\support/type_algorithms.h(52,23): note: in instantiation of function template specialization 'test()::(anonymous class)::operator()<char>' requested here
   52 |   swallow((f.template operator()<Types>(), 0)...);
      |                       ^
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp(161,10): note: in instantiation of function template specialization 'types::for_each<char, int, TriviallyComparable<char>, (lambda at D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last.pass.cpp:161:77)>' requested here
  161 |   types::for_each(types::type_list<char, int, TriviallyComparable<char>>{}, []<class T> {
      |          ^
Click to expand first error for ranges.find_last_if.pass.cpp:
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last_if.pass.cpp(62,32): error: cannot cast from type 'iterator' (aka '_Array_iterator<int, 0>') to pointer type 'const std::_Array_iterator<int, 0> *'
   62 |   return std::ranges::subrange(It(std::ranges::begin(a)), Sent(It(std::ranges::end(a))));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last_if.pass.cpp(101,44): note: in instantiation of function template specialization 'make_range<const std::_Array_iterator<int, 0> *, const std::_Array_iterator<int, 0> *, std::array<int, 0>>' requested here
  101 |       auto ret = std::ranges::find_last_if(make_range<it, sent>(a), [](auto&&) { return true; }).begin();
      |                                            ^
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last_if.pass.cpp(191,3): note: in instantiation of function template specialization 'test_iterator_classes<add_const_to_ptr_t, std::type_identity_t>' requested here
  191 |   test_iterator_classes<add_const_to_ptr_t, std::type_identity_t>();
      |   ^
Click to expand first error for ranges.find_last_if_not.pass.cpp:
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last_if_not.pass.cpp(62,32): error: cannot cast from type 'iterator' (aka '_Array_iterator<int, 0>') to pointer type 'const std::_Array_iterator<int, 0> *'
   62 |   return std::ranges::subrange(It(std::ranges::begin(a)), Sent(It(std::ranges::end(a))));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last_if_not.pass.cpp(101,48): note: in instantiation of function template specialization 'make_range<const std::_Array_iterator<int, 0> *, const std::_Array_iterator<int, 0> *, std::array<int, 0>>' requested here
  101 |       auto ret = std::ranges::find_last_if_not(make_range<it, sent>(a), [](auto&&) { return false; }).begin();
      |                                                ^
D:\GitHub\STL\llvm-project\libcxx\test\std\algorithms\alg.nonmodifying\alg.find.last\ranges.find_last_if_not.pass.cpp(191,3): note: in instantiation of function template specialization 'test_iterator_classes<add_const_to_ptr_t, std::type_identity_t>' requested here
  191 |   test_iterator_classes<add_const_to_ptr_t, std::type_identity_t>();
      |   ^
@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 25, 2024
@strega-nil
Copy link
Contributor

Mmh, I had intended to make this work with non-pointer iterators; I apparently incorrectly wrote that code and it was not caught in testing. Let me fix this, thanks for finding it!

strega-nil added a commit that referenced this issue Jul 30, 2024
In the tests I added for `ranges::find_last{_if{_not}}`, I accidentally
introduced an assumption that `same_as<array<T, 0>::iterator, T*>`; this
is a faulty assumption on MSVC-STL.

Fixes #100498.
banach-space pushed a commit to banach-space/llvm-project that referenced this issue Aug 7, 2024
In the tests I added for `ranges::find_last{_if{_not}}`, I accidentally
introduced an assumption that `same_as<array<T, 0>::iterator, T*>`; this
is a faulty assumption on MSVC-STL.

Fixes llvm#100498.
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. test-suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants