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

<algorithm>: Fix bogus pointer arithmetic with integer-class #5091

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Nov 16, 2024

By using ptrdiff_t when the related value is guaranteed to be small enough and/or used in pointer arithmetic. Fixes #2885.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner November 16, 2024 09:24
auto vw = views::iota(I{}, static_cast<I>(ranges::size(a)))
| views::transform([&a](I i) -> auto& { return a[static_cast<size_t>(i)]; });

static_assert(three_way_comparable<ranges::iterator_t<ranges::iota_view<I>>>); // TRANSITION, /permissive
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is really weird. It seems that MSVC doesn't evaluate concept specializations as quickly as required in permissive modes.

Copy link
Member

Choose a reason for hiding this comment

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

From the last bit of the error log:

D:\build\out\inc\__msvc_ranges_to.hpp(865): note: while evaluating concept 'three_way_comparable<std::ranges::_Ioterator<signed char>,std::partial_ordering>'
D:\build\out\inc\__msvc_ranges_to.hpp(865): error C2131: expression did not evaluate to a constant
D:\build\out\inc\__msvc_ranges_to.hpp(865): note: failure was caused by a read of an uninitialized symbol
D:\build\out\inc\__msvc_ranges_to.hpp(865): note: see usage of 'std::three_way_comparable<std::ranges::_Ioterator<_Wi>,std::partial_ordering>'

"C2131 while evaluating meow ... see usage of meow" generally suggests constraint recursion, which is not that unusual in permissive mode. The fact the overload resolution sees "extra" friend overloads that ought to be hidden can easily trigger constraint recursion.

@CaseyCarter CaseyCarter added bug Something isn't working ranges C++20/23 ranges labels Nov 16, 2024
@StephanTLavavej StephanTLavavej self-assigned this Nov 16, 2024
Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

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

Just some tweaks that I'll apply.

stl/inc/algorithm Outdated Show resolved Hide resolved
auto vw = views::iota(I{}, static_cast<I>(ranges::size(a)))
| views::transform([&a](I i) -> auto& { return a[static_cast<size_t>(i)]; });

static_assert(three_way_comparable<ranges::iterator_t<ranges::iota_view<I>>>); // TRANSITION, /permissive
Copy link
Member

Choose a reason for hiding this comment

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

From the last bit of the error log:

D:\build\out\inc\__msvc_ranges_to.hpp(865): note: while evaluating concept 'three_way_comparable<std::ranges::_Ioterator<signed char>,std::partial_ordering>'
D:\build\out\inc\__msvc_ranges_to.hpp(865): error C2131: expression did not evaluate to a constant
D:\build\out\inc\__msvc_ranges_to.hpp(865): note: failure was caused by a read of an uninitialized symbol
D:\build\out\inc\__msvc_ranges_to.hpp(865): note: see usage of 'std::three_way_comparable<std::ranges::_Ioterator<_Wi>,std::partial_ordering>'

"C2131 while evaluating meow ... see usage of meow" generally suggests constraint recursion, which is not that unusual in permissive mode. The fact the overload resolution sees "extra" friend overloads that ought to be hidden can easily trigger constraint recursion.

stl/inc/algorithm Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ranges C++20/23 ranges
Projects
Status: Final Review
Development

Successfully merging this pull request may close these issues.

<algorithm>: ranges::stable_sort missing difference_type casting for pointer arithmetic
3 participants