This is an archive of the discontinued LLVM Phabricator instance.

[libc++][expected] Implement LWG3836
ClosedPublic

Authored by yronglin on Jul 19 2023, 6:39 AM.

Details

Reviewers
ldionne
huixie90
Mordante
Group Reviewers
Restricted Project
Commits
rG96377e5cc1e3: [libc++][expected] Implement LWG3836
Summary

Implement LWG3836 (https://wg21.link/LWG3836)
std::expected<bool, E1> conversion constructor expected(const expected<U, G>&) should take precedence over expected(U&&) with operator bool

Diff Detail

Event Timeline

yronglin created this revision.Jul 19 2023, 6:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 6:39 AM
yronglin requested review of this revision.Jul 19 2023, 6:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 6:39 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
yronglin edited the summary of this revision. (Show Details)Jul 19 2023, 6:41 AM
yronglin added reviewers: ldionne, huixie90.
yronglin edited the summary of this revision. (Show Details)

Seems std::optional does not have this issue https://godbolt.org/z/96T5MT695

Does this have test for all changes paragraphs in the LWG issue?

libcxx/include/__expected/expected.h
181

This was needed for C++03.

227

We typically don't mention LWG numbers in the code. We use them in the tests.

libcxx/include/optional
735

likewise

yronglin marked 3 inline comments as done.Jul 26 2023, 9:06 AM

Thanks for your review and sorry for the very late reply!

libcxx/include/__expected/expected.h
181

Thanks for the tip, does the header file for C++23 also need this?

227

Thanks, I'll remove this.

Thanks for your review and sorry for the very late reply!

No problem, I was quite busy with the release the last week.

libcxx/docs/Status/Cxx23Issues.csv
293

We missed the LLVM 17 deadline.

libcxx/include/__expected/expected.h
181

In C++23 we can use >>>>.

libcxx/include/optional
735

I still see the LWG number.

yronglin updated this revision to Diff 545399.Jul 29 2023, 8:44 PM
yronglin marked 2 inline comments as done.

Address comments.

yronglin marked 2 inline comments as done.Jul 29 2023, 8:48 PM

Does this have test for all changes paragraphs in the LWG issue?

For std::expected, seems @huixie90 has ever add a test in ctor.u.pass.cpp.
For std::optional, I can't reproduce this issue, but I have followed the standard wording.

I finally found time to have a closer look at the patch. In general happy but I would like more test coverage to see things are correct.

@huixie90 it would be great when you also can have a look at this patch.

libcxx/include/__expected/expected.h
171–180

Why not something like this? This looks closer to the wording in the issue. It saves the reader from doing mental boolean calculations when comparing the code against the wording in the standard.

I would also more the new condition down so again it's closer to the wording of the standard. The new paragraph 23.5 is also added at the end and not in between.

226–227

Not your change but this matches the order of the wording in the WP.

libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.u.pass.cpp
141–149

There are 5 changes in the wording, can you make sure there are tests for all changes?

yronglin updated this revision to Diff 547455.Aug 5 2023, 12:06 AM
yronglin marked an inline comment as done.

Address comments.

yronglin marked 2 inline comments as done.Aug 5 2023, 12:15 AM

Thanks a lot for your review! @Mordante

libcxx/include/__expected/expected.h
171–180

Seems the converts-from-any-cvref<T, expected<U, G>> is false only performed when if T is not cv bool it true, we can't put s_same<remove_cv_t<_Tp>, bool> and converts-from-any-cvref<T, expected<U, G>> in the same conjunction expression, because the result was not correct. Can we use _If here?, it's more closing to the wording. WDYT?

226–227

Thanks, this looks good, done!

libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.u.pass.cpp
141–149

Thanks for your tips, I have add more test cases.

yronglin updated this revision to Diff 547490.Aug 5 2023, 8:25 AM
yronglin marked 2 inline comments as done.

Address comment, use _If to get closer to the standard wording.

ping~

I've been quite busy. I'll hope to have time to look at this patch and D154116 later this week.

ping~

I've been quite busy. I'll hope to have time to look at this patch and D154116 later this week.

Thanks!

Mordante accepted this revision.Aug 19 2023, 4:04 AM

LGTM after a minor fix.

libcxx/include/__expected/expected.h
178–179

Some whitespace fixed. This is not done by clang-format since that breaks in C++03.

This revision is now accepted and ready to land.Aug 19 2023, 4:04 AM
yronglin updated this revision to Diff 551759.Aug 19 2023, 8:19 AM

Addres comment.

yronglin marked an inline comment as done.Aug 19 2023, 8:20 AM

Thanks a lot for your review! @Mordante

libcxx/include/__expected/expected.h
178–179

Thanks, fixed.

This revision was automatically updated to reflect the committed changes.
yronglin marked an inline comment as done.