Skip to content

chunk_by_view's helper lambda returns bool - #2890

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
cpplearner:patch-1
Aug 5, 2022
Merged

chunk_by_view's helper lambda returns bool#2890
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
cpplearner:patch-1

Conversation

@cpplearner

@cpplearner S. B. Tam (cpplearner) commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

Fixes #2889

Casey's drive-by: Give up on the Standard's dream that we can avoid defining projected::operator*. There are just too many interactions with the "need for constant evaluation" rules and the use of types with internal linkage - it's not worth fighting anymore.

@cpplearner
S. B. Tam (cpplearner) requested a review from a team as a code owner July 20, 2022 08:25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are missing some additional test coverage.

Comment thread stl/inc/ranges Outdated
Comment thread stl/inc/ranges

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Removing my approval as I do not believe it correctly implements the standard.

Comment thread stl/inc/ranges
Comment thread stl/inc/ranges
Comment thread tests/std/tests/P2443R1_views_chunk_by/test.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It definitely took a bit to convince me that this is correct, but I have now been convinced.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small suggestions, of which we have enough that I think I should push changes.

Comment thread stl/inc/ranges
Comment thread tests/std/tests/P2443R1_views_chunk_by/test.cpp Outdated
Comment thread tests/std/tests/P2443R1_views_chunk_by/test.cpp Outdated
Comment thread stl/inc/ranges
@CaseyCarter Casey Carter (CaseyCarter) removed their assignment Aug 4, 2022
Comment thread stl/inc/xutility
#else // ^^^ no workaround / workaround vvv
indirect_result_t<_Proj&, _It> operator*() const {
_CSTD abort(); // TRANSITION, VSO-1308657
_CSTD abort();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For reviewers:

projected is a tool to simplify expressing the requirements of algorithms that use projections. The design intent is that the member functions don't have definitions - they are just signatures that exist for iter_reference_t et al. to look at. This hasn't worked well in practice in the real world, as witnessed by the warning suppressions for clang and MSVC around the definition, the additional bug report (VSO-1308657) mentioned there, and the fact that it broke yet again when I made Bool a local class in that PR. The PR uses projected<Bool*, identity>, and clang-cl decided to report an error about operator* being used-but-not-defined when it can't possibly be defined in another TU since Bool has internal linkage. Rather than trying to find yet another workaround for this perennial issue (four or five changes here in ~3 years?) I decided to give up and simply always define operator* to call abort. The function should never be called in practice, so even if it does end up emitted into some object files the linker should be able to clean it up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am sad about projected::operator*, but cools.

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 9ed0e6b into microsoft:main Aug 5, 2022
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for fixing this compiler error and improving the ranges experience! 😻 🐞 🎉

@cpplearner
S. B. Tam (cpplearner) deleted the patch-1 branch August 6, 2022 03:26
nicole mazzuca (strega-nil) pushed a commit to strega-nil/stl that referenced this pull request Aug 6, 2022
Co-authored-by: Casey Carter <Casey@Carter.net>
Igor Zhukov (fsb4000) pushed a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
Co-authored-by: Casey Carter <Casey@Carter.net>
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

None yet

Development

Successfully merging this pull request may close these issues.

<ranges>: chunk_by_view's helper lambda does not specify return type

8 participants